Errow while updating

Posted by Jammyhunt under ASP.NET on 7/28/2013 | Points: 10 | Views : 2039 | Status : [Member] | Replies : 15
Can anybody tell me what is wrong with this code??

ac = Request.QueryString["ac_no"];
OleDbCommand com = new OleDbCommand();
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|daksh.mdb;Persist Security Info=False;");
com.Connection = con;
com.Connection.Open();
com.CommandText = "UPDATE general set recover amount='" + total + "' WHERE ac no=ac";
com.ExecuteNonQuery();
con.Close();




Responses

Posted by: aswinialuri-19361 on: 7/28/2013 [Member] Starter | Points: 25

Up
0
Down
then what is your Exception

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 7/28/2013 [Member] Starter | Points: 25

Up
0
Down
this is my exeption

Exception Details: System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.

Source Error:

Line 39: com.Connection.Open();
Line 40: com.CommandText = "UPDATE general set recover amount =" + total+ " WHERE ac no =" + ac;
Line 41: com.ExecuteNonQuery(); Line 42: con.Close();
Line 43: }

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 7/28/2013 [Member] Starter | Points: 25

Up
0
Down
that doesnt work too @jitendra

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 7/28/2013 [Member] Starter | Points: 25

Up
0
Down
that doesnt work too

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ssj_Kumar on: 7/29/2013 [Member] Starter | Points: 25

Up
0
Down
use the below content it will work
"UPDATE general set [recover amount] =" + total+ " WHERE [ac no] =" + ac;

Regards,
Jayakumar Selvakani

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 7/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Try the query by using quotenames for the columns ( Recover amount, ac no) i.e. [recover amount], [ac no]
"UPDATE general set recover amount='" + total + "' WHERE ac no=ac";

Still do you have error? then check the following
what are the data types of total, ac ? Are these variables compatible with your table columns?
One example for update table in MS-access using C#
http://stackoverflow.com/questions/4986426/updating-an-ms-access-table-in-c-sharp

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 8/3/2013 [Member] Starter | Points: 25

Up
0
Down
still cant find solution for my update command

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 8/3/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Give us all the names of the fields in the table general

Thank you for posting at Dotnetfunda
[Administrator]

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 8/4/2013 [Member] Starter | Points: 25

Up
0
Down


this is my general table

i want to update recover amount column using ac no in where clause..

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 8/4/2013 [Member] Starter | Points: 25

Up
0
Down
fresh posted here with all required things to solve this problem
http://www.dotnetfunda.com/forums/thread15847-help-in-updation-of-table.aspx

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 8/4/2013 [Member] Starter | Points: 25

Up
0
Down
dont know why but this code doesnt work for me

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 8/4/2013 [Member] Starter | Points: 25

Up
0
Down
ok download this file from below link.

http://www.mediafire.com/download/29djd37hxpm7mrg/tosend.rar
Run it and open default.apsx after that click on acount details column. which will redirect you to gend.aspx page.... here i calculated total of amount column, And i want to update general table with this total. general table get show on the page default.aspx

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 8/5/2013 [Member] Starter | Points: 25

Up
0
Down
Bro have you tested on your system?... because it still doesnt work for me

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Instead of total use amt variable for recover amount.... i.e. you should convert TextBox (total) value to double/int as per your input values before using that text box value in the UPDATE statement for recovery amount.
Make sure to have ac variable of type string in the code.
Label lbl = (Label)e.Row.FindControl("total");

lbl.Text = total.ToString();


double amt = Convert.ToDouble(total);

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|daksh.mdb;Persist Security Info=true;");
OleDbCommand com = new OleDbCommand("UPDATE general set [recover amount] =" + amt + " WHERE [ac no] = '" + ac + "'", con);


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jammyhunt on: 8/5/2013 [Member] Starter | Points: 25

Up
0
Down
i have already tried that but still same error..
i have provided source code of my project can you look at it and rectify errors
please

Jammyhunt, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response