Update Command Syntax Error [Resolved]

Posted by Cibin under VB.NET on 5/8/2013 | Points: 10 | Views : 13354 | Status : [Member] | Replies : 6
Can you help me out,,, I am using Visual Studio 2010 ultimate with MS Access as Back end,, In the update query am getting an error message as "Syntax error in UPDATE statement." ... But i cant see any errors in this,,,,

My Code is :

str2 = "UPDATE prepaidcosims SET Name='" & TextBox5.Text & "', Designation='" & ComboBox11.Text & "', MobileNo='" & TextBox7.Text & "', Site='" & ComboBox5.Text & "', Date='" & TextBox12.Text & "', Remarks='" & TextBox9.Text & "' WHERE Fileno='" & ComboBox8.Text & "'"

Please help me




Responses

Posted by: Satyapriyanayak on: 5/8/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Try

str2 = "UPDATE prepaidcosims SET Name='" & TextBox5.Text & "', Designation='" & ComboBox11.Text & "', MobileNo='" & TextBox7.Text & "', Site='" & ComboBox5.Text & "', [Date]='" & TextBox12.Text & "', Remarks='" & TextBox9.Text & "' WHERE Fileno='" & ComboBox8.Text & "'"


If this post helps you mark it as answer
Thanks

If this post helps you mark it as answer
Thanks

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

Posted by: Kmandapalli on: 5/8/2013 [Member] Silver | Points: 25

Up
0
Down
hi,

Try to modify your code in this way...
Dim sql As String = "UPDATE prepaidcosims SET Name=@Name, Designation=@Designation, MobileNo=@MobileNo,
Site=@Site, Date=@Date, Remarks=@ Remarks WHERE Fileno=@Fileno"
Dim sqlcommand As New SqlClient.SqlCommand
With sqlcommand
.CommandType = CommandType.Text
.CommandText = sql
.Connection = connection
.Parameters.AddWithValue("@Name", Name)
.Parameters.AddWithValue("@Designation", Designation)
.Parameters.AddWithValue("@MobileNo", MobileNo)
.Parameters.AddWithValue("@Site", Site)
.Parameters.AddWithValue("@Date", Date)
.Parameters.AddWithValue("@Remarks", Remarks)
.Parameters.AddWithValue("@Fileno", Fileno)
End With

Mark as Answer if satisfied......

Regards,
Shree M.

Kavya Shree Mandapalli

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

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

Up
0
Down
This is in SQL,, But am Using MS Access as Back end using OLEDB

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

Posted by: Kmandapalli on: 5/8/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

The synatx for UPDATE statement is same in SQL and in OLEDB.
Instead of SQL, use OLEDB.
Somewhat Like this......
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.jet.OLEDB.4.0;Data Source=C:\amardeep\db1.mdb;User Id=admin;Password=;";
con.Open();
string query = "UPDATE prepaidcosims SET Name=@Name, Designation=@Designation, MobileNo=@MobileNo,
Site=@Site, Date=@Date, Remarks=@ Remarks WHERE Fileno=@Fileno" ;
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.Parameters.AddWithValue("@Name",TextBox5.Text );
cmd.Parameters.AddWithValue("@Designation", ComboBox11.Text);
cmd.Parameters.AddWithValue("@MobileNo", TextBox7.Text );
cmd.Parameters.AddWithValue("@Site", ComboBox5.Text);
cmd.Parameters.AddWithValue("@Date", TextBox12.Text);
cmd.Parameters.AddWithValue("@Remarks", TextBox9.Text);
cmd.Parameters.AddWithValue("@Fileno", ComboBox8.Text);
int x = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("your data has been Updated");

Mark as Answer if satisfied......

Regards,
Shree M.

Kavya Shree Mandapalli

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

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

Up
0
Down
I tried,,, But Same Error Existing,and also am using this in vb.net, OK ,, Thanks in Advance

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

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

Up
0
Down
Thank You So Muchhhhhh


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

Login to post response