Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/11/2008, 11:08
AndresFelipeG
 
Fecha de Ingreso: agosto-2008
Ubicación: Medellín
Mensajes: 20
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: No me ejecuta el metodo

pero cuando pongo directamente el codigo en el método del boton si me funciona.
Código:
SqlConnection con = new SqlConnection("Data Source=Server;Initial Catalog=BaseDatos;User ID=sa;Password=123");

 protected void Button1_Click(object sender, EventArgs e)
    {
       
             
        if ((flimage.PostedFile != null) && (flimage.PostedFile.ContentLength > 0))
        {
            if (flimage.Value.EndsWith(".dat"))
            {
                if (flimage.PostedFile.ContentLength <= 50000)
                {
                    string fn = System.IO.Path.GetFileName(flimage.PostedFile.FileName);
                    string SaveLocation = Server.MapPath(@"~\Temporal") + "\\" + fn;
                    try
                    {

                        this.Label1.Text = "El archivo se ha cargado.";
                        this.lblmessage.Text = "";
                        flimage.PostedFile.SaveAs(SaveLocation);
                        con.Open();
                         SqlCommand command = new SqlCommand("Create table Temporal (CodigoAcceso nchar(10))", con);
                         SqlCommand command1 = new SqlCommand("BULK INSERT Temporal FROM '" + SaveLocation + "' ", con);
                         SqlCommand command2 = new SqlCommand("INSERT into IngresoLector (IDEjemplar) Select IDEjemplar from Ejemplares E, Temporal tem where E.CodigoAcceso = tem.CodigoAcceso COLLATE Modern_Spanish_CI_AS", con);
                         SqlCommand command4 = new SqlCommand("set ansi_nulls off", con);
                         SqlCommand command3 = new SqlCommand("update IngresoLector SET  FechaConsulta = getdate() WHERE FechaConsulta = NULL;", con);
                         SqlCommand command5 = new SqlCommand("drop table Temporal", con);
                         command.ExecuteNonQuery();
                         command1.ExecuteNonQuery();
                         command2.ExecuteNonQuery();
                         command4.ExecuteNonQuery();
                         command3.ExecuteNonQuery();
                         command5.ExecuteNonQuery();
                         con.Close();
                     
                        // this.lblmessage.Text = "El archivo se ha cargado.";
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);

                    }
                }
                else
                   
                    this.Label1.Text = "El tamaño del archivo debe ser menor a 50kbs";

            }
            else
                
                this.lblmessage.Text = "No se pudo cargar el archivo seleccionado, por favor seleccione una imagen .jpg, .gif o .png";
        }
        else
        {
            
            this.lblmessage.Text = "Seleccione un archivo que cargar.";
        }

    }
 }
Muchas gracias cualquier ayuda