Click here to Skip to main content
15,881,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hiii...
C#
SqlConnection con = new SqlConnection(cn.ConnectionStrings);
            GridViewRow row = (GridViewRow)grdLead.Rows[e.RowIndex];
            int userid = Convert.ToInt32(grdLead.DataKeys[e.RowIndex].Value.ToString());
            Label lblLedId = (Label)grdLead.FindControl("lblLedId");
            TextBox txtleadid = (TextBox)row.Cells[0].Controls[0];
            TextBox txtfirstname = (TextBox)row.Cells[1].Controls[0];
            TextBox txtdate = (TextBox)row.Cells[5].Controls[0];
            TextBox txtstatus = (TextBox)row.Cells[6].Controls[0];
            TextBox txtrevenue=(TextBox)row.Cells[3].Controls[0];
            TextBox txtproduct=(TextBox)row.Cells[4].Controls[0];
            TextBox txtowner = (TextBox)row.Cells[7].Controls[0];
            TextBox txtcompany = (TextBox)row.Cells[2].Controls[0];
            GridView1.EditIndex = -1;
            con.Open();
            string QUERY=" UPDATE [WebCrm].[dbo].[tbl_Lead] SET FirstName='" + txtfirstname.Text + "', Date='" +Convert.ToDateTime(txtdate.Text) + "', Status='" + txtstatus.Text + "',PotentialRevenue='" + txtrevenue.Text + "',ProductInterest='" + txtproduct.Text + "', Owner='" + txtowner.Text + "',Company='" + txtcompany.Text + "' where LedId=" + userid + "";
            SqlCommand cmd = new SqlCommand(QUERY, con);
            cmd.ExecuteNonQuery();
            con.Close();
Posted
Updated 18-Oct-15 19:11pm
v2

1 solution

Check the value inside TextBox txtdate = (TextBox)row.Cells[5].Controls[0]; is a proper date time.
Use CONVERT[^] on the SQL Server side or DateTime.TryParse[^] on the client side to confirm date format is correct.

In addition, passing field names directly is never a good idea because of SQL injection[^].
 
Share this answer
 
Comments
Maciej Los 19-Oct-15 2:53am    
5ed!
Abhinav S 19-Oct-15 3:17am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900