Datagridview Duplicate Record Merge

mcitp

New member
Joined
May 2, 2021
Messages
2
Programming Experience
Beginner
hello how do we write similar coded data in datagridview by summing the number in a single line

C#:
private void cmbBarkod_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    SqlConnection con = bgl.baglantim();
                    SqlCommand cmd = new SqlCommand("Select * from S where msg_S_0078='" + cmbBarkod.Text + "'", con);
                    int _parameter = Convert.ToInt32(cmd.ExecuteScalar());
                    con.Close();
                    if (_parameter == 0)
                    {
                        MessageBox.Show("Bu Barkoda Ait Ürün Bulunmamaktadır", "UYARI",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    }
                    else
                    {
                        getir();
                    }
                }
                catch(Exception EX)
                {
                    MessageBox.Show(EX.Message, "UYARI");
                }
            }
            Hesapla();
        }
        void getir()
        {
            bgl.Reader2("select * from S where msg_S_0078='" + cmbBarkod.Text + "'", datagrid_veriler, "msg_S_0078", "msg_S_0870", "PERAKENDE", adet);
            cmbBarkod.Text = string.Empty;
        }

data.png
 
Last edited by a moderator:
Why don't you use the DISTINCT keyword in your SQL statement?

As a quick aside, concatenating a string like that for a SQL statement is setting yourself up for a potential SQL injection attack down the road. Yes, you may control the string values that can go in right now with your combobox, what if somewhere down the road some just copies and pastes your code, or changes the combobox to an edit control, or a combobox that takes user inputs. Suddenly your strings are not under your control anymore. Obligatory SQL injection cartoon:

exploits_of_a_mom.png
 
Back
Top Bottom