how to update a row in data grid ??
-
I am trying to update row in sql database 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 !!
-
I am trying to update row in sql database 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 !!
Why all The mess Why not just using the : SqlDataAdaptor i've been using OdbcDataAdaptor, & OledbDataadaptor and it's easy no 100 Line codes, but half and even less Try it It's actually creates a conector betwen your DB and your Data Grid :)
Have Fun Never forget it
-
Why all The mess Why not just using the : SqlDataAdaptor i've been using OdbcDataAdaptor, & OledbDataadaptor and it's easy no 100 Line codes, but half and even less Try it It's actually creates a conector betwen your DB and your Data Grid :)
Have Fun Never forget it
-
ya i know its really using OledbDataadaptor but my database is not in MS Access but in Sql Server... so everything i need to write is using sql commands .. can u help me with that ?
-
ya i know its really using OledbDataadaptor but my database is not in MS Access but in Sql Server... so everything i need to write is using sql commands .. can u help me with that ?