Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Why the data are not updating in table.
My cs coading is given below
C#
void submit(Object s, EventArgs e)
{
con.Open();
com=con.CreateCommand();
if(con!=null)
{
com.CommandText="UPDATE joining SET aname = '" + txtName.Text.Trim() + "',fathname='" +   txtFather.Text.Trim()+ "' where refno='" + txtRefNo.Text.Trim() + "'";
try{
com.ExecuteNonQuery();
System.Web.UI.WebControls.Label lbl1=new System.Web.UI.WebControls.Label();
lbl1.ForeColor=System.Drawing.Color.Yellow;
lbl1.BackColor=System.Drawing.Color.Blue;
lbl1.Text="Your record UPDATED sucessfully";
ph1.Controls.Add(lbl1);
}
catch(Exception ex)
{
Response.Write(ex.Message);
}}
con.Close();
}
Posted
Updated 20-Jan-12 21:43pm
v2

1 solution

There are a numbers of problems with you code.

First _DO_ not build SQL statements like you do. Use SqlParamenter[^], but why?
See http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html[^]

But lets say that you SQL update statement is correct. Then it all depends on you WHERE clause.
Is there a record you table 'joining' that has 'refno' matching the one applied?

Are there any exceptions, what does 'com.ExecuteNonQuery()' returns ?
 
Share this answer
 
v2

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