Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I have a search button and datagrid in c# and SQL

I have a search button and datagrid in c# and SQL

Scheduled Pinned Locked Moved C#
databasecsharpsecurityhelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    antonio_dsanchez
    wrote on last edited by
    #1

    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

    it is my code

    conexion.ConnectionString = @"Data Source = SHINIL-PC040\SQLEXPRESS; Initial Catalog = produccion; Integrated Security = True";
    if(TXTORDEN_PRODUCCION.Text == "" || TXTTURNO.Text == "" || TXTMAQUINAS.Text == "" || TXTHORAINICIO.Text == "" || TXTHORAFIN.Text == "")
    {
    MessageBox.Show("Te falta campo");
    }
    else
    {

                if (checkBox1.Checked == true)  
                {  
                    try  
                    {  
    
                        comando.Connection = conexion;  
                        conexion.Open();  
                        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 ";  
                        // "SELECT MOLDE, PROYECTO, ITEMPARTE, COLOR, SNP FROM PARTE WHERE ITEMPARTE = @ITEMPARTE";  
                        SqlCommand cmd = new SqlCommand(SqlAction, conexion);  
                        cmd.Parameters.AddWithValue("@orden", TXTORDEN\_PRODUCCION.Text);  
                        cmd.Parameters.AddWithValue("@turno", TXTTURNO.Text);  
                        cmd.Parameters.AddWithValue("@maquina", TXTMAQUINAS.Text);  
                        cmd.Parameters.AddWithValue("@horainicio", TXTHORAINICIO.Text);  
                        cmd.Parameters.AddWithValue("@horafin", TXTHORAFIN.Text);  
    
                         
                        }  
    
                        conexion.Close();  
                    }  
                    
                    catch (Exception Ex)  
                    {  
                        MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);  
                    }  
                }  
                MessageBox.Show("selecciono ok produccion");  
                }  
                if (checkBox2.Checked == true)  
                {  
                    MessageBox.Show("selecciono paros");  
                }  
                if (checkBox1.Checked == false & checkBox2.Checked == false)  
                {
    
    D A 2 Replies Last reply
    0
    • A antonio_dsanchez

      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

      it is my code

      conexion.ConnectionString = @"Data Source = SHINIL-PC040\SQLEXPRESS; Initial Catalog = produccion; Integrated Security = True";
      if(TXTORDEN_PRODUCCION.Text == "" || TXTTURNO.Text == "" || TXTMAQUINAS.Text == "" || TXTHORAINICIO.Text == "" || TXTHORAFIN.Text == "")
      {
      MessageBox.Show("Te falta campo");
      }
      else
      {

                  if (checkBox1.Checked == true)  
                  {  
                      try  
                      {  
      
                          comando.Connection = conexion;  
                          conexion.Open();  
                          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 ";  
                          // "SELECT MOLDE, PROYECTO, ITEMPARTE, COLOR, SNP FROM PARTE WHERE ITEMPARTE = @ITEMPARTE";  
                          SqlCommand cmd = new SqlCommand(SqlAction, conexion);  
                          cmd.Parameters.AddWithValue("@orden", TXTORDEN\_PRODUCCION.Text);  
                          cmd.Parameters.AddWithValue("@turno", TXTTURNO.Text);  
                          cmd.Parameters.AddWithValue("@maquina", TXTMAQUINAS.Text);  
                          cmd.Parameters.AddWithValue("@horainicio", TXTHORAINICIO.Text);  
                          cmd.Parameters.AddWithValue("@horafin", TXTHORAFIN.Text);  
      
                           
                          }  
      
                          conexion.Close();  
                      }  
                      
                      catch (Exception Ex)  
                      {  
                          MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);  
                      }  
                  }  
                  MessageBox.Show("selecciono ok produccion");  
                  }  
                  if (checkBox2.Checked == true)  
                  {  
                      MessageBox.Show("selecciono paros");  
                  }  
                  if (checkBox1.Checked == false & checkBox2.Checked == false)  
                  {
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You never asked a question.

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • A antonio_dsanchez

        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

        it is my code

        conexion.ConnectionString = @"Data Source = SHINIL-PC040\SQLEXPRESS; Initial Catalog = produccion; Integrated Security = True";
        if(TXTORDEN_PRODUCCION.Text == "" || TXTTURNO.Text == "" || TXTMAQUINAS.Text == "" || TXTHORAINICIO.Text == "" || TXTHORAFIN.Text == "")
        {
        MessageBox.Show("Te falta campo");
        }
        else
        {

                    if (checkBox1.Checked == true)  
                    {  
                        try  
                        {  
        
                            comando.Connection = conexion;  
                            conexion.Open();  
                            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 ";  
                            // "SELECT MOLDE, PROYECTO, ITEMPARTE, COLOR, SNP FROM PARTE WHERE ITEMPARTE = @ITEMPARTE";  
                            SqlCommand cmd = new SqlCommand(SqlAction, conexion);  
                            cmd.Parameters.AddWithValue("@orden", TXTORDEN\_PRODUCCION.Text);  
                            cmd.Parameters.AddWithValue("@turno", TXTTURNO.Text);  
                            cmd.Parameters.AddWithValue("@maquina", TXTMAQUINAS.Text);  
                            cmd.Parameters.AddWithValue("@horainicio", TXTHORAINICIO.Text);  
                            cmd.Parameters.AddWithValue("@horafin", TXTHORAFIN.Text);  
        
                             
                            }  
        
                            conexion.Close();  
                        }  
                        
                        catch (Exception Ex)  
                        {  
                            MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);  
                        }  
                    }  
                    MessageBox.Show("selecciono ok produccion");  
                    }  
                    if (checkBox2.Checked == true)  
                    {  
                        MessageBox.Show("selecciono paros");  
                    }  
                    if (checkBox1.Checked == false & checkBox2.Checked == false)  
                    {
        
        A Offline
        A Offline
        antonio_dsanchez
        wrote on last edited by
        #3

        the Question is, as can I load the data back my search datagrid

        S P 2 Replies Last reply
        0
        • A antonio_dsanchez

          the Question is, as can I load the data back my search datagrid

          S Offline
          S Offline
          Swinkaran
          wrote on last edited by
          #4

          Sorry, but can you ask your question in more detail? What exactly are you trying to achieve?

          1 Reply Last reply
          0
          • A antonio_dsanchez

            the Question is, as can I load the data back my search datagrid

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Yes you can. Loading the DataGrid is not a one time only operation.

            This space for rent

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups