Click here to Skip to main content
11,570,741 members (51,987 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Why the data are not updating in table.
My cs coading is given below
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 20-Jan-12 21:39pm
Edited 20-Jan-12 21:43pm
ambarishtv10.5K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 ?
  Permalink  
v2

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 21 Jan 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100