narayana_anthati Posted October 16, 2006 Share Posted October 16, 2006 Hai , I got problem with updation of datagrid.It editing but when we press update it is not working.Plz Help me it's very urgent.Thanks in advance.Here i am sending my code:protected void datagrid1_UpdateCommand(object source, DataGridCommandEventArgs e) { System.Web.UI.WebControls.TextBox cName = new System.Web.UI.WebControls.TextBox(); cName = (System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]; SqlCommand mycommand = new SqlCommand("SP_Updatecategorylist", conn); mycommand.CommandType = CommandType.StoredProcedure; mycommand.Parameters.Add(new SqlParameter("@categorylist", SqlDbType.NVarChar, 50)); mycommand.Parameters["@categorylist"].Value = cName.Text; conn.Open(); mycommand.ExecuteNonQuery(); conn.Close(); datagrid1.EditItemIndex = -1; BindData(); }Stored Procedure:CREATE PROCEDURE SP_Updatecategorylist @categorylist nvarchar(50) AS UPDATE categorylist SET categorylist = @categorylist WHERE categorylist = @categorylist; Link to comment Share on other sites More sharing options...
aspnetguy Posted October 16, 2006 Share Posted October 16, 2006 what about is not working? Is it not updating hte database? Is it inserting a blank value? Do you get error messages?Please be as specific as possible. Link to comment Share on other sites More sharing options...
jesh Posted October 16, 2006 Share Posted October 16, 2006 And what is the purpose of that SQL query? UPDATE categorylist SET categorylist = @categorylist WHERE categorylist = @categorylist; Set categorylist = @categorylist WHERE categorylist = @categorylist? That's like set 5 = 5 WHERE 5 = 5, isn't it? Link to comment Share on other sites More sharing options...
aspnetguy Posted October 16, 2006 Share Posted October 16, 2006 And what is the purpose of that SQL query?UPDATE categorylist SET categorylist = @categorylist WHERE categorylist = @categorylist; Set categorylist = @categorylist WHERE categorylist = @categorylist? That's like set 5 = 5 WHERE 5 = 5, isn't it? That is the way I see it...and the code does too :)that query is completely pointless and does nothing...probably the source of your troubles... Link to comment Share on other sites More sharing options...
narayana_anthati Posted October 16, 2006 Author Share Posted October 16, 2006 Hai , I got problem with updation of datagrid.It editing but when we press update it is not working.Plz Help me it's very urgent.Thanks in advance.Here i am sending my code:protected void datagrid1_UpdateCommand(object source, DataGridCommandEventArgs e) { System.Web.UI.WebControls.TextBox cName = new System.Web.UI.WebControls.TextBox(); cName = (System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]; SqlCommand mycommand = new SqlCommand("SP_Updatecategorylist", conn); mycommand.CommandType = CommandType.StoredProcedure; mycommand.Parameters.Add(new SqlParameter("@categorylist", SqlDbType.NVarChar, 50)); mycommand.Parameters["@categorylist"].Value = cName.Text; conn.Open(); mycommand.ExecuteNonQuery(); conn.Close(); datagrid1.EditItemIndex = -1; BindData(); }Stored Procedure:CREATE PROCEDURE SP_Updatecategorylist @categorylist nvarchar(50) AS UPDATE categorylist SET categorylist = @categorylist WHERE categorylist = @categorylist; Hai, It is not giving any error but but when we click the update button it just coming back as before with out any updation.If ypu have any code please send me it's very urgent.Regardsnarayana Link to comment Share on other sites More sharing options...
aspnetguy Posted October 16, 2006 Share Posted October 16, 2006 the problem is your stored procedure. You need to pass something to identify the record you want to update like the primary key or something and use that as the WHERE clause instead. Link to comment Share on other sites More sharing options...
pulpfiction Posted October 16, 2006 Share Posted October 16, 2006 CREATE PROCEDURE SP_Updatecategorylist @categorylist nvarchar(50) AS UPDATE categorylist SET categorylist = @categorylist WHERE categorylist = @categorylist;According to this SP, you send a parameter to the SP and see in the table, fieldname [categorylist] has that value,If it has the value then update it with the same parameter value.it will be the same value, i dont see any update.....Pls check your stored procedure... Link to comment Share on other sites More sharing options...
narayana_anthati Posted October 17, 2006 Author Share Posted October 17, 2006 CREATE PROCEDURE SP_Updatecategorylist @categorylist nvarchar(50) AS UPDATE categorylist SET categorylist = @categorylist WHERE categorylist = @categorylist;According to this SP, you send a parameter to the SP and see in the table, fieldname [categorylist] has that value,If it has the value then update it with the same parameter value.it will be the same value, i dont see any update.....Pls check your stored procedure...If any body having sample code plz send me its very urgent or plz rectify my problem please.Regardsnarayana Link to comment Share on other sites More sharing options...
jesh Posted October 17, 2006 Share Posted October 17, 2006 What everyone is saying is that you need to change your Stored Procedure so that you look up the category based on some unique identifier (that doesn't change). Perhaps something like this: CREATE PROCEDURE SP_Updatecategorylist(@CategoryID int,@CategoryName varchar(50))ASUPDATE categorylist SET CategoryName = @CategoryName WHERE CategoryID = @CategoryID Perhaps the SQL Tutorial might help. Link to comment Share on other sites More sharing options...
narayana_anthati Posted October 18, 2006 Author Share Posted October 18, 2006 What everyone is saying is that you need to change your Stored Procedure so that you look up the category based on some unique identifier (that doesn't change). Perhaps something like this:CREATE PROCEDURE SP_Updatecategorylist(@CategoryID int,@CategoryName varchar(50))ASUPDATE categorylist SET CategoryName = @CategoryName WHERE CategoryID = @CategoryID Perhaps the SQL Tutorial might help. Thanks now it workingRegardsnarayana Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now