Click here to Skip to main content
15,667,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagrigview connected to a database. I want to delete record from datagridview, if i select record and press the delete button the record deleted, But if i close app and start it again the record still appear and the record below i selected has been deleted.
can any one tell me what's wrong..
dataadapter.DeleteCommand = new SqlCeCommand("delete from Glasses where id= '" + (((DataRowView)bindingsources.Current).Row[9].ToString()) + "'");
Updated 14-Sep-13 8:13am
abbaspirmoradi 14-Sep-13 13:14pm    
Becuase you just delete row from datagrigview not from the database..
PIEBALDconsult 14-Sep-13 13:32pm    
"I have a datagrigview connected to a database"

Ah, but you don't; there are several layers in between. One of which is a DataTable, on which you probably need to AcceptChanges. And another of which may be a DataAdapter, on which you probably need to Update.

All-in-all; you may find database work easier if you avoid DataAdapters.

Try this:
string deletestr = "delete from Glasses where id= '" +
                              (((DataRowView)bindingsources.Current).Row[9].ToString()) + "'";

           using (SqlCommand sqlCmd = new SqlCommand(deletestr, SqlConnction))

                catch (Exception)
                  //show error

Share this answer
Member 9557321 14-Sep-13 13:31pm    
there is no error opining connection or execute query.
abbaspirmoradi 14-Sep-13 13:46pm    
get your query string and test it in sqlQuery in your sql sever management studio..
Member 9557321 14-Sep-13 14:33pm    
no error in query string
Check the value as the follows:
string value_ID = ((DataRowView)bindingsources.Current).Row[9].ToString();

I think the value won't be the id value what you are looking for.

The other solution can be if you delete the single quotes from your delete script.
Share this answer
Member 9557321 14-Sep-13 14:09pm    
yes dear i checked it and it returns the id for below record i have selected
i don't know why!!
norbitrial 15-Sep-13 4:30am    
The other solution can be if you delete the single quotes from your delete script.

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