Update Datagrid
-
Hi, I'm trying to update a datagrid using SqlCommand updateBuilding=new SqlCommand("UPDATE Buildings SET bName ='"+e.Item.Cells[3].Text+"',bAddress ='"+e.Item.Cells[4].Text+"',bState ='"+e.Item.Cells[5].Text+"',bCity ='"+e.Item.Cells[6].Text+"',bZip ='"+e.Item.Cells[7].Text+"' where (bCode ='"+e.Item.Cells[2].Text+"')",conn); where e is System.Web.UI.WebControls.DataGridCommandEventArgs It doesn't work.After I put a break point and looked in the debug window this is what I saw: "UPDATE Buildings SET bName ='',bAddress ='',bState ='',bCity ='',bZip ='' where (bCode ='')" Any ideas? Thanks
-
Hi, I'm trying to update a datagrid using SqlCommand updateBuilding=new SqlCommand("UPDATE Buildings SET bName ='"+e.Item.Cells[3].Text+"',bAddress ='"+e.Item.Cells[4].Text+"',bState ='"+e.Item.Cells[5].Text+"',bCity ='"+e.Item.Cells[6].Text+"',bZip ='"+e.Item.Cells[7].Text+"' where (bCode ='"+e.Item.Cells[2].Text+"')",conn); where e is System.Web.UI.WebControls.DataGridCommandEventArgs It doesn't work.After I put a break point and looked in the debug window this is what I saw: "UPDATE Buildings SET bName ='',bAddress ='',bState ='',bCity ='',bZip ='' where (bCode ='')" Any ideas? Thanks
-
Maybe it's just because we need to write a tag with a backslash before when you write a string, that way: "\'". Oren.
it was like this ((TextBox)e.Item.Cells[4].Controls[0]).Text Now..i have an other problem After I hit the edit button, it doesn't enter the edit mode..it shows only plain text.here is the code. private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.EditItemIndex=e.Item.ItemIndex; BindGrid(); } void BindGrid() { SqlCommand fillGrid=new SqlCommand("Select * from Tenants",conn); fillGrid.Connection.Open(); DataGrid1.DataSource=fillGrid.ExecuteReader(); DataGrid1.DataBind(); fillGrid.Connection.Close(); }