I have one webpage developed in C# asp.net. Here, I have gridview which is binded to my table1. UserDetails columns are id, userID, user name I have another DashbaordData having columns - data1, data2, and createdby.
here input data of createdby column from DashbardData and userID from userDetails are the same.
I want to delete record from DashbardData , from the row deleting event of gridview (which is binded to userDetails) on the where condition of DashbardData .createdby=userDetails.userID.
protected void GridView1_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
{
try
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Label id = (Label)row.FindControl("lblRecordID");
Label userID = (Label)row.FindControl("lbluserID");
OleDbConnection con = new OleDbConnection(conDB);
OleDbCommand cmd1 = new OleDbCommand();
cmd1.CommandText = "delete* from DashboardData where Createdby =" + userID.Text + "";
cmd1.Connection = con;
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
Here in code, i am getting the userID value from userdetails table which is binded to gridview, and passing that userID to delete query to delete record from Dashbaordata table.
In debug i see that query is correct, it is picking up the correct value but when it execute cmd1.ExecuteNonQuery(); nothing happnes. it goes to catch section and give error as parameters not found.
I have doubt whether we can do like this- deleting another table record using row deleting event of some different table gridview ?
could you please help me how I can do it.