C# Syntax Error In Update Statement
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this ms access syntax error in update statement site About Us Learn more about Stack Overflow the company Business Learn more oledbexception syntax error in update statement about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x syntax error in update statement. c# + access Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Syntax error syntax error in update statement vba in UPDATE statement OleDb Exception up vote 0 down vote favorite I check my SQL Statement many times and it seems that my SQL Statement is Error. I don't why it doesn't work. My SQL Statement is correct and It resulted to this OleDBException "Syntax error in UPDATE statement.". Here is the code OleDbConnection CN = new OleDbConnection(mysql.CON.ConnectionString); CN.Open(); cmd1 = new OleDbCommand("Update Mosque
Syntax Error In Update Statement Oledb
Set Name='" + txtNAME.Text + "', No='" + Convert.ToInt32(txtNO.Text) + "', place='" + txtPlace.Text + "', group='" + txtGroup.Text + "', description='" + txtdec.Text + "' where id='" + txtID.Text + "'", CN); cmd1.ExecuteNonQuery(); CN.Close(); need help please to know what is the error here c# mysql sql share|improve this question edited Sep 26 '13 at 19:47 marc_s 451k938631029 asked Sep 26 '13 at 19:42 user2746526 3218 How does the update statement looks like? Can you break it. I advise to store the query first into a string variable. Make debugging more easy. –Jeroen van Langen Sep 26 '13 at 19:46 @user2746526 Please save your cmd1 to a string varialbe and print it out for us to see the final result. –Vulcronos Sep 26 '13 at 19:51 1 You really need to check what the string value of txtName.Text is before placing it in the query. You are extremely prone to a SQL Injection by placing the variable directly into the query. This is a major vulnerability and bound to cause your queries to fail. –JNYRanger Sep 26 '13 at 19:51 add a comment| 2 Answer
here for a quick overview of the site Help Center Detailed
Syntax Error In Update Statement Vb6
answers to any questions you might have Meta Discuss the c# syntax error in insert into statement workings and policies of this site About Us Learn more about Stack Overflow the company syntax error in update statement vb.net access Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join http://stackoverflow.com/questions/19037263/syntax-error-in-update-statement-oledb-exception the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up C# - Syntax Error in UPDATE Statement up vote 0 down vote favorite I'm trying to update a database using C#, but http://stackoverflow.com/questions/10854208/c-sharp-syntax-error-in-update-statement I get the error: "Syntax error in UPDATE statement". I've looked around for other examples of this error, and found plenty, but every one is different. A lot of things can cause this error, and I just can't put my finger on this one. query = String.Format(@"UPDATE PAYMENT SET MONTANT={0}, TYPE='4-Comptant',note='PPA',flag='O', date='{2:yyyyMMdd}' WHERE num_payment={1}", -payment, id, dt); daUpdate.UpdateCommand.CommandText = query; daUpdate.UpdateCommand.ExecuteNonQuery(); //update the table in the database In debug mode, this is what the string ends up looking like: UPDATE PAYMENT SET MONTANT=-390, TYPE='4-Comptant',note='PPA',flag='O', date='20120601' WHERE num_payment=8 In the database, num_payment is a long integer and a primary key. MONTANT is a double, everything else is text. Edit: Following people's advice, I've modified things a bit, but I'm still getting the same error. Here's what it looks like now: OleDbCommand cmd = _con.CreateCommand(); cmd.CommandText = @"UPDATE PAYMENT SET MONTANT=@montant, [TYPE]='4-Comptant',note='PPA',flag='O', [date]=@theDate WHERE num_payment=@numPayment"; cmd.Parameters.AddWithValue("@montant", -payment); cmd.Para
here for a quick overview of the site Help Center Detailed answers to any questions you might have http://stackoverflow.com/questions/30008383/syntax-error-in-update-statement-oledbexception Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just syntax error like you, helping each other. Join them; it only takes a minute: Sign up Syntax error in UPDATE statement OleDbException up vote 0 down vote favorite I'm writing an application which stores user information. Currently the user is supposed to update their Name, Height, Weight and Birthday. string height = TB_ClientHeight.Text; string weight = TB_ClientWeight.Text; string name syntax error in = TB_ClientName.Text; string bday = dateTimePicker1.Value.ToString("dd-MM-yyyy"); int heightint = Convert.ToInt32(height); int weightint = Convert.ToInt32(weight); It's updated by calling the public static string username variable from another form and using that as the WHERE UserName = @username. usernamestringo = Login.usernameFromLogin; I've followed other SO answers in this context and corrected some issues (like preventing SQL Injection). However I'm still getting a syntax error while updating these fields as claimed by OleDbException. using (OleDbConnection myCon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=O:\Repos\Database\Database.accdb;Persist Security Info=False")) using (OleDbCommand cmd = new OleDbCommand()) { cmd.CommandType = CommandType.Text; string query = "UPDATE TPersons SET Name=@Name, SET Height=@Height, SET Weight=@Weight, SET Bday=@Bday " + " WHERE FirstName= @username"; cmd.CommandText = query; cmd.Parameters.AddWithValue("@Name", name.ToString()); cmd.Parameters.AddWithValue("@Height", heightint.ToString()); cmd.Parameters.AddWithValue("@Weight", weightint.ToString()); cmd.Parameters.AddWithValue("@Bday", bday.ToString()); cmd.Parameters.AddWithValue("@username", usernamestringo); cmd.Connection = myCon; myCon.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("Updated!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); cmd.Parameters.Clear(); } The OleDbException is: Index #0 NativeError: -526847407 Source: Microsoft Access Database Engine SQLState: 3000 Description (message): Syntax error in UPDATE statement. Could anyone guide me where my syntax is wrong? Thank you! c# sql ol