Errow while updating

Posted by Jammyhunt under ASP.NET on 7/28/2013 | Points: 10 | Views : 1177 | Status : [Member] | Replies : 23
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: Jitendrasoft09 on: 7/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Jammyhunt,

You can not keep space between the word, please try to modify your code as below and must keep your code inside Exception to understand exact error.

com.CommandText = "UPDATE general set recover_amount='" + total + "' WHERE ac_no=ac"; 


Hope you are clear.

Jitendra Kumar
If my post helps you, plz mark as an answer.

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: Jitendrasoft09 on: 7/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Jammyhunt,

One code is missing as below, please add following code to execute-

com.CommandText = "UPDATE general set recover_amount ='" + total + "' WHERE ac_no =ac"; 

com.CommandType = CommandType.Text;

Hope you are clear.


Jitendra Kumar
If my post helps you, plz mark as an answer.

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: Jitendrasoft09 on: 7/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Jammyhunt,

One code is missing as below, please add following code to execute-

com.CommandText = "UPDATE general set recover_amount ='" + total + "' WHERE ac_no =ac"; 

com.CommandType = CommandType.Text;


Refer below link for understanding more-
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtext.aspx
Hope you are clear.

Jitendra Kumar
If my post helps you, plz mark as an answer.

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: Jitendrasoft09 on: 8/3/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Jammyhunt,

Tell us what is the exact error not only say update is not working, as above mentioned note that to use exception to get exact information. Put the breakpoint and see what is the reason update is not working.

Hope you will get solutions.



Jitendra Kumar
If my post helps you, plz mark as an answer.

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: Jitendrasoft09 on: 8/4/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Jammyhunt,

As you can not use '=' operator if your are using text datatype to compare the value.

Modify your code as below mentioned-

UPDATE general set [recover amount] =" + total+ " WHERE [ac no] LIKE '"+ 'ac +"'

Hope you have understood.

Jitendra Kumar
If my post helps you, plz mark as an answer.

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: Jitendrasoft09 on: 8/4/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Jammyhunt,

As I have tried for same is working for me. You send your complete code, will modify and send back to you.

Jitendra Kumar
If my post helps you, plz mark as an answer.

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: Jitendrasoft09 on: 8/4/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Jammyhunt,

Nice coding. Modify your code as below will work perfectly.

 if (e.Row.RowType == DataControlRowType.Footer)

{
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] =" + total + " WHERE [ac no] LIKE '" + ac + "'", con);

con.Open();

com.ExecuteNonQuery();
con.Close();
}


Hope you are clear.

Jitendra Kumar
If my post helps you, plz mark as an answer.

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

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

Up
0
Down
Dear All,

Please find below working code that is tested in my application-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class gend : System.Web.UI.Page
{
decimal total;
string ac;
protected void Page_Load(object sender, EventArgs e)
{
ac = Request.QueryString["ac_no"];

}

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal rowtotal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "amount"));
total = total + rowtotal;

}

if (e.Row.RowType == DataControlRowType.Footer)
{
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] =" + total + " WHERE [ac no] LIKE '" + ac + "'", con);

con.Open();

com.ExecuteNonQuery();
con.Close();
}

}

}


Hope you have understood.

Jitendra Kumar
If my post helps you, plz mark as an answer.

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

Login to post response