Click here to Skip to main content
15,849,328 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi,

I have a datagridview with a check box column as the first column in it.

I want the users to select multiple check boxes and on a button click event, an SQL update query should be executed based on the values from the second column of the datagridview.

Example query : Update table set confirm=0 where empname in ('Mike','Jack')

Mike and Jack are the selections by the user using the check box column.

Please suggest me a solution for this.

Thanks in advance
Posted

Hi All,

I got the solution finally.


C#
for (int i = 0; i < dtgrdUnconfirm.Rows.Count; i++)
                {
                    DataGridViewCheckBoxCell clmSelect = new DataGridViewCheckBoxCell();
                    clmSelect = (DataGridViewCheckBoxCell)dtgrdUnconfirm.Rows[i].Cells[0];                 
                    if (clmSelect.Value != null &&
                           Convert.ToBoolean(clmSelect.Value) == true)
                    {
                        data += (dtgrdUnconfirm.Rows[i].Cells[6].Value.ToString())+",";                        
                    }                    
                }
                data = data.TrimEnd(',');                
                if (lstbxUnconfirm.SelectedItem.ToString() == "ID")
                {
                    updatesql = "update tablename set Confirmed=0 where id in (" + data + ")";
                }
 
Share this answer
 
please describe your problem properly
 
Share this answer
 
Comments
Rahul Krishnan R 23-Sep-13 1:02am    
More Details =>

User selected Mike and Jack as shown in the image (please find the link below):

When pressing the Un-Confirm button, I want to execute the below query.

Update table set confirm=0 where empname in ('Mike','Jack')


http://www.flickr.com/photos/29783979@N08/9890393166/lightbox/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900