Дубликат значения в datagridview
i want to check the duplicate values in the datagridview . and if their is duplicate value then error message to user. if no duplicate value then select query will run . for that i am using following code , but needs some modification for meeting my requirement .....
value in the DGV is entered through Combobox which is being displayed in first column in the DGV . Thanks in advance .....
Что я уже пробовал:
for (int i = 1; i <= dataGridView1.Rows.Count - 1; i++) { if (comboBox1.Text == dataGridView1.Rows[i].Cells[0].Value) { MessageBox.Show("entered value already exist in table"); return; } } con.Open(); string sql = "select USERID,PARTY , PARTY_NO,DATE from dgvdata where id ='" + comboBox1.Text + "'"; System.Data.SqlClient.SqlDataAdapter dataadapter = new System.Data.SqlClient.SqlDataAdapter(sql, con); DataTable dt = new DataTable(); dataadapter.Fill(dt); dataGridView1.Rows[index].Cells["USERID"].Value = dt.Rows[0]["USERID"].ToString(); dataGridView1.Rows[index].Cells["Party"].Value = dt.Rows[0]["Party"].ToString(); dataGridView1.Rows[index].Cells["Party_No"].Value = dt.Rows[0]["Party_No"].ToString(); dataGridView1.Rows[index].Cells["Date"].Value = dt.Rows[0]["DATE"].ToString(); con.close(); }
Karthik_Mahalingam
можете ли вы опубликовать скриншот своей сетки?
imgur.com