Jump to content

datagrid Updating Problem


narayana_anthati

Recommended Posts

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

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

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

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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...