Datagrid Update
-
Hello, I am working on a datagrid update... when I click on edit, I can get the textboxes but when I make the changes and click on the update button, I still have the old items in there... .can someone help? here is the code for my update command: string cursusname, niveau, plaats, start, end, dip, finance,pers_id, afdeling, cursusID; cursusname = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[5].Controls[0]).Text; niveau= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[6].Controls[0]).Text; plaats= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].Controls[0]).Text; start = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[8].Controls[0]).Text; end= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[9].Controls[0]).Text; dip = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[10].Controls[0]).Text; finance= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[11].Controls[0]).Text; pers_id= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[0].Controls[0]).Text; afdeling= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0]).Text; cursusID= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[4].Controls[0]).Text; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=sqloledb;Data Source=SQL_SERVER;Initial Catalog=Intra_STUDENT;User Id=student;Password=student"); string sql = "UPDATE P_Cursus SET " + "CursusNaam='"+cursusname+"', " + "Niveau="+niveau+", "+ "Plaats='"+plaats+"',"+ "StartDatum='" + start + "',"+ "EindDatum='" + end + "', "+ "Diploma='" + dip + "', "+ "Financiering='"+finance+"' WHERE personeel_id="+pers_id+" AND Personeel_filliaal_afdeling ="+afdeling+" AND cursus_id = "+cursusID+""; System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(sql,conn); myCommand.CommandType = CommandType.Text; conn.Open(); myCommand.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; DataGrid1.DataBind();
-
Hello, I am working on a datagrid update... when I click on edit, I can get the textboxes but when I make the changes and click on the update button, I still have the old items in there... .can someone help? here is the code for my update command: string cursusname, niveau, plaats, start, end, dip, finance,pers_id, afdeling, cursusID; cursusname = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[5].Controls[0]).Text; niveau= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[6].Controls[0]).Text; plaats= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].Controls[0]).Text; start = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[8].Controls[0]).Text; end= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[9].Controls[0]).Text; dip = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[10].Controls[0]).Text; finance= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[11].Controls[0]).Text; pers_id= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[0].Controls[0]).Text; afdeling= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0]).Text; cursusID= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[4].Controls[0]).Text; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=sqloledb;Data Source=SQL_SERVER;Initial Catalog=Intra_STUDENT;User Id=student;Password=student"); string sql = "UPDATE P_Cursus SET " + "CursusNaam='"+cursusname+"', " + "Niveau="+niveau+", "+ "Plaats='"+plaats+"',"+ "StartDatum='" + start + "',"+ "EindDatum='" + end + "', "+ "Diploma='" + dip + "', "+ "Financiering='"+finance+"' WHERE personeel_id="+pers_id+" AND Personeel_filliaal_afdeling ="+afdeling+" AND cursus_id = "+cursusID+""; System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(sql,conn); myCommand.CommandType = CommandType.Text; conn.Open(); myCommand.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; DataGrid1.DataBind();
It's because you're not resetting the datasource of the gridview to the new updated dataset before binding.
-
It's because you're not resetting the datasource of the gridview to the new updated dataset before binding.