ASP.NET - Actualizar datos

 
Vista:

Actualizar datos

Publicado por Carlos (1 intervención) el 29/11/2006 23:57:17
Hola a todos

He hecho aplicaciones para Windows pero soy nuevo en ASP y me topé con un problema. Hice una webform para capturar datos y almacenarlos en una base de datos SQL y lo hace sin problemas, ahora estoy haciendo una webform para actualizarlos, pero cuando oprimo el botó de submit me gurada los valores anteriores.

He puesto el evento OnTextChange en uno de los textbox para ver su valor en la depuración, cuando cambio el valor del textbox el evento se dispara pero sigue conservando el valor anterior.

Alguien podría ayudarme y decirme por qué pasa esto?

No tengo ni idea donde pueda estar el error, pero aquí les pongo el codigo


/ /Conexión al servidor
cnxLINKSISTEMAS = new SqlConnection("Data Source=(local);Initial Catalog=linksistemas;Persist Security Info=True;User ID=Carlos; password=dbsmpt");

/ /Codigo del producto (enviado en la url de la pagina)
Codigo = Request.QueryString.Get("codigo");

/ /Comando para obtener las promociones
SqlDataAdapter daPromocion = new SqlDataAdapter("SELECT * FROM Promociones LEFT JOIN Imagenes ON PRO_Codigo = IMA_CodigoObjeto WHERE PRO_Codigo = '" + Codigo + "'", cnxLINKSISTEMAS);
dsPromocion = new DataSet();
daPromocion.Fill(dsPromocion, "Promocion");

lbCodigoPromocion.Text = Codigo;
txtTitulo.Text = dsPromocion.Tables["Promocion"].Rows[0]["PRO_Titulo"].ToString();
txtDescripcionCorta.Text = dsPromocion.Tables["Promocion"].Rows[0]["PRO_DescripcionCorta"].ToString();
txtDescripcionLarga.Text = dsPromocion.Tables["Promocion"].Rows[0]["PRO_DescripcionLarga"].ToString();
txtCaracteristicas.Text = dsPromocion.Tables["Promocion"].Rows[0]["PRO_Caracteristicas"].ToString();
txtPrecioNormal.Text = dsPromocion.Tables["Promocion"].Rows[0]["PRO_PrecioNormal"].ToString();
if (dsPromocion.Tables["Promocion"].Rows[0]["PRO_PrecioOferta"] != DBNull.Value)
txtPrecioOferta.Text = dsPromocion.Tables["Promocion"].Rows[0]["PRO_PrecioOferta"].ToString();
}

public string RutaImagenesDestino = "C:\\Inetpub\\wwwroot\\linsys\\imagenes\\";

protected void btnGuardar_Click(object sender, EventArgs e)
{

/ /Valor del precio de oferta, validando en caso de que no haya precio de oferta (NULL)
string PrecioOferta = "NULL";
if (txtPrecioOferta.Text != "")
PrecioOferta = txtPrecioOferta.Text;

/ /*********************************************************************************
/ / Validación de los archivos a subri
/ /*********************************************************************************

/ /Animación
string Animacion = dsPromocion.Tables["Promocion"].Rows[0]["PRO_RutaAnimacion"].ToString();
if (fupAnimacion.HasFile)
if (fupAnimacion.PostedFile.ContentType != "application /x-shockwave-flash")
{
lbErrorAnimacion.Text = "Solo animaciones SWF";
return;
}
else
{
try
{
fupAnimacion.SaveAs("C:\\Inetpub\\wwwroot\\linsys\\promociones\\animaciones\\" + fupAnimacion.FileName);
Animacion = ".. /promociones /animaciones /" + fupAnimacion.FileName;
}
catch (Exception ex)
{
lbErrorAnimacion.Text = "ERROR: " + ex.Message.ToString();
return;
}
}

/ /Imagen Principal
string ImagenPrincipal = dsPromocion.Tables["Promocion"].Rows[0]["PRO_RutaImagenPrincipal"].ToString();
if (fupImagenPrincipal.HasFile)
if (EsArchivoValido(fupImagenPrincipal) != "")
{
lbErrorImgPrincipal.Text = EsArchivoValido(fupImagenPrincipal);
return;
}
else
{
try
{
fupImagenPrincipal.SaveAs(RutaImagenesDestino + fupImagenPrincipal.FileName);
ImagenPrincipal = ".. /imagenes /" + fupImagenPrincipal.FileName;
}
catch (Exception ex)
{
lbErrorImgPrincipal.Text = "ERROR: " + ex.Message.ToString();
return;
}
}

SqlCommand cmdUpDatePromocion = new SqlCommand("UPDATE Promociones SET PRO_Titulo = '" + txtTitulo.Text + "', " +
"PRO_DescripcionCorta = '" + txtDescripcionCorta.Text + "', " +
"PRO_DescripcionLarga = '" + txtDescripcionLarga.Text + "', " +
"PRO_Caracteristicas = '" + txtCaracteristicas.Text + "', " +
"PRO_PrecioNormal = " + txtPrecioNormal.Text + ", " +
"PRO_PrecioOferta = " + PrecioOferta + ", " +
"PRO_RutaAnimacion = '" + Animacion + "', " +
"PRO_RutaImagenPrincipal = '" + ImagenPrincipal + "'" +
"WHERE PRO_Codigo = '" + Codigo + "'", cnxLINKSISTEMAS);

cnxLINKSISTEMAS.Open();
cmdUpDatePromocion.ExecuteNonQuery();
cnxLINKSISTEMAS.Close();

Response.Redirect(".. /management /editarpromociones.aspx");
}

public string EsArchivoValido(FileUpload fupValidando)
{
string Error = "";
HttpPostedFile UploadingFile = fupValidando.PostedFile;
if (File.Exists(RutaImagenesDestino + fupValidando.FileName))
Error = "Ya existe una imagen con ese nombre";
else if (UploadingFile.ContentType != "image /jpeg" && UploadingFile.ContentType != "image /pjpeg" && UploadingFile.ContentType != "image /gif")
Error = "Solo imégenes de tipo jpg o gif";
else if (UploadingFile.ContentLength > 51200)
Error = "La imagen no debe pesar más de 50 Kb";
else if (new Bitmap(UploadingFile.InputStream).Width != 150 || new Bitmap(UploadingFile.InputStream).Height != 150)
Error = "La imagen debe tener las dimensiones de 150px por 150px";
return Error;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder