how to update a row in data grid ?? [modified]
-
i am trying to update row in table (data grid ) but unable to do it .. this is what i have done so far .. protected void UpdateCommand(object source, DataGridCommandEventArgs e) { Response.Write("testing"); SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); string database1 = "Level1"; TextBox UserName = (TextBox)(e.Item.Cells[2].Controls[0]); TextBox MacAddr = (TextBox)(e.Item.Cells[3].Controls[0]); DataSet ds = new DataSet(); SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn); myCommand.Connection = conn; myCommand.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(ex.Message); Response.End(); if (conn != null) conn.Close(); return; } finally { Response.Redirect((string)Session["PreviousURL"]); } conn.Close(); DataGrid1.EditItemIndex = -1; can someone help me how to update after we clik edit button in each textbox in a row ?? Thanx !! -- modified at 11:39 Tuesday 6th November, 2007
-
i am trying to update row in table (data grid ) but unable to do it .. this is what i have done so far .. protected void UpdateCommand(object source, DataGridCommandEventArgs e) { Response.Write("testing"); SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); string database1 = "Level1"; TextBox UserName = (TextBox)(e.Item.Cells[2].Controls[0]); TextBox MacAddr = (TextBox)(e.Item.Cells[3].Controls[0]); DataSet ds = new DataSet(); SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn); myCommand.Connection = conn; myCommand.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(ex.Message); Response.End(); if (conn != null) conn.Close(); return; } finally { Response.Redirect((string)Session["PreviousURL"]); } conn.Close(); DataGrid1.EditItemIndex = -1; can someone help me how to update after we clik edit button in each textbox in a row ?? Thanx !! -- modified at 11:39 Tuesday 6th November, 2007
rocky811 wrote:
i am trying to update row in sql database
rocky811 wrote:
SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn);
You can't do that unless you understand the Basic's of SQL. I would reccomend you to go through the Basic's Of SQL Commands.[^]
Regards
- J O H N -
-
rocky811 wrote:
i am trying to update row in sql database
rocky811 wrote:
SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn);
You can't do that unless you understand the Basic's of SQL. I would reccomend you to go through the Basic's Of SQL Commands.[^]
Regards
- J O H N -
-
Database doesn't have rows. Only tables in the Database can contain Row's. what is that you are trying to do exactly in that code? I have sent you a link to Read the Basic's of SQL Command. If you go through it you will understand how to write a UPDATE statement in SQL.
Regards
- J O H N -
-
Database doesn't have rows. Only tables in the Database can contain Row's. what is that you are trying to do exactly in that code? I have sent you a link to Read the Basic's of SQL Command. If you go through it you will understand how to write a UPDATE statement in SQL.
Regards
- J O H N -
-
sorry !! i mistyped it !!! i actually wanted to update a row in table.. i have a data grid with few columns in it . I want to edit each row and update it . when i try to click edit button it shows an exception (Invalid Operation) . Hope u got it now..
Here is the syntax of the UPDATE statement used to make changes to the existing records in table.
update tablename set columnname = newvalue [,columnxname = newvaluex...] where columnname OPERATOR value [and|or columnnamex OPERATOR valuex]
Compare this syntax with your UPDATE statement and check whether you have given it right.Regards
- J O H N -