antonio sanchez

antonio sanchez

  • NA
  • 24
  • 3.5k

I have a search button and datagrid in c#

Oct 11 2016 5:00 PM
hi all
 
I have a search button and datagrid in c#, I require perform a query in the database and load the data in me datagrid
 
the Question is, as can I load the data back my search datagrid
 
 
it is my code
 
  1. conexion.ConnectionString = @"Data Source = SHINIL-PC040\SQLEXPRESS; Initial Catalog = produccion; Integrated Security = True";  
  2.             if(TXTORDEN_PRODUCCION.Text == "" || TXTTURNO.Text == "" || TXTMAQUINAS.Text == "" || TXTHORAINICIO.Text == "" || TXTHORAFIN.Text == "")  
  3.             {  
  4.                 MessageBox.Show("Te falta campo");  
  5.             }  
  6.             else  
  7.             {  
  8.                  
  9.                 if (checkBox1.Checked == true)  
  10.                 {  
  11.                     try  
  12.                     {  
  13.   
  14.                         comando.Connection = conexion;  
  15.                         conexion.Open();  
  16.                         string SqlAction = "select orden, turno, operador, horainicio, horafin, articulo, totalpiezasok, totalcajas, piezascondefecto, maquina from conteo2 where CONVERT(varchar(10), horafin, 108) >= @horainicio and CONVERT(varchar(10), horafin, 108)<= @horafin and orden = @orden  and turno = @turno and maquina = @maquina ";  
  17.                         // "SELECT MOLDE, PROYECTO, ITEMPARTE, COLOR, SNP FROM PARTE WHERE ITEMPARTE = @ITEMPARTE";  
  18.                         SqlCommand cmd = new SqlCommand(SqlAction, conexion);  
  19.                         cmd.Parameters.AddWithValue("@orden", TXTORDEN_PRODUCCION.Text);  
  20.                         cmd.Parameters.AddWithValue("@turno", TXTTURNO.Text);  
  21.                         cmd.Parameters.AddWithValue("@maquina", TXTMAQUINAS.Text);  
  22.                         cmd.Parameters.AddWithValue("@horainicio", TXTHORAINICIO.Text);  
  23.                         cmd.Parameters.AddWithValue("@horafin", TXTHORAFIN.Text);  
  24.   
  25.                          
  26.                         }  
  27.   
  28.                         conexion.Close();  
  29.                     }  
  30.                     
  31.                     catch (Exception Ex)  
  32.                     {  
  33.                         MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);  
  34.                     }  
  35.                 }  
  36.                 MessageBox.Show("selecciono ok produccion");  
  37.                 }  
  38.                 if (checkBox2.Checked == true)  
  39.                 {  
  40.                     MessageBox.Show("selecciono paros");  
  41.                 }  
  42.                 if (checkBox1.Checked == false & checkBox2.Checked == false)  
  43.                 {  
  44.                     MessageBox.Show("tiene que seleccionar un reporte");  
  45.                 }  
  46.             }  
 

Answers (2)