Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 04, 2012 12:43 AM by CommDev
Nov 29, 2012 02:05 PM|LINK
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
int Eid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
System.Web.UI.WebControls.TextBox name = (System.Web.UI.WebControls.TextBox)GridView1.Rows[e.RowIndex].FindControl("FName");
System.Web.UI.WebControls.TextBox address = (System.Web.UI.WebControls.TextBox)GridView1.Rows[e.RowIndex].FindControl("LName");
System.Web.UI.WebControls.TextBox designation = (System.Web.UI.WebControls.TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmail");
string ename = name.Text;
string eaddress = address.Text;
string edesignation = designation.Text;
SqlCommand cmd = new SqlCommand("Update Regis Set FName='"+ename+"',LName='"+eaddress+"',Email='"+edesignation+"' where Sno='"+Eid+"'", con);
GridView1.EditIndex = -1;
Hi i didnt know where mistake pls anyone help me...
i need row updating in gridview asp.net c#...Thank you
Nov 29, 2012 02:15 PM|LINK
My suggestion to you is set a breakpoint at int Eid and step through the code using the debugger. watch the values because this error means you have a null value.
Nov 29, 2012 02:23 PM|LINK
Nov 29, 2012 02:24 PM|LINK
Hi, no null value in database y the error occur
Nov 29, 2012 02:26 PM|LINK
Your update statement should look like this:
"Update Regis Set FName='+"ename"+',LName='+"eaddress"+',Email='+"edesignation"+' where Sno='+"Eid"+'"
(I moved over the + symbols).
You should probably be using parameters though. This is not the safest way to pass in values to sql query
Nov 29, 2012 03:11 PM|LINK
Its worked but no changes when update anyone can help me
Nov 29, 2012 03:19 PM|LINK
Nevermind, set your query back to the way you had it originally. I was thinking of ename, eaddress etc as strings but they are variables. Sorry about that
Nov 29, 2012 03:22 PM|LINK
You didn't define what con is, your connection object. Should be something like:
SqlConnection con = new SqlConnection(yourconnstring);
Nov 29, 2012 03:30 PM|LINK
ya (ie) sql connection string
Nov 29, 2012 03:32 PM|LINK
But you haven't declared it as an actual SqlConnection object. It doens't know what it is. Just try it the way I'm telling you to. I have over 10 years experience in dot net development. Another user also mentioned this as well.