Click here to Skip to main content
15,886,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Update queries not updating records and also not giving any error.But this programe is fetching records during page load but when i want to update that records it is not working and also not giving error.Please help me.

If some setting for folder which have all files or mdb file for the update query please also mention.



<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<%@Page Language="C#" Debug="true" %>
<script runat="server">
OleDbConnection con;
OleDbCommand com;
OleDbDataAdapter da;
DataSet ds;
void page_Load(Object sender,EventArgs e)
{
con=new OleDbConnection();
con.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/kamnagroup.mdb") + "";
con.Open();
ds=new DataSet();
string sql="select aname,fathname,refno FROM joining";
da=new OleDbDataAdapter(sql,con);
da.Fill(ds,"joining");
DataRow dRow=ds.Tables["joining"].Rows[0];
t1.Text =dRow.ItemArray.GetValue(0).ToString();
t2.Text = dRow.ItemArray.GetValue(1).ToString();
t3.Text = dRow.ItemArray.GetValue(2).ToString();
con.Close();
}
void Submit(Object s, EventArgs e)
{con.Close();
con.Open();
ds=new DataSet();
com=con.CreateCommand();
com.CommandText="UPDATE joining SET aname = '" + t1.Text.Trim() + "',fathname='" + t2.Text.Trim() + "' where refno='" + t3.Text.Trim() + "'";
com.CommandText="UPDATE joining SET aname = @NAME,fathname=@FATHER WHERE refno=@REFNO";
com.Parameters.AddWithValue("@NAME",t1.Text.Trim());
com.Parameters.AddWithValue("@FATHER",t2.Text.Trim());
com.Parameters.AddWithValue("@REFNO",t3.Text.Trim());
try{int count=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();
}
</script>
Posted

1 solution

Check if REFNO is a string type or a number type.
 
Share this answer
 
Comments
Janardan Pandey 31-Jan-12 4:28am    
it is a string type

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