Oledb Oledbexception Syntax Error
Contents |
here for a quick overview of the site system.data.oledb.oledbexception (0x80004005) Help Center Detailed answers to any questions you might
Syntax Error In Insert Into Statement. Oledb C#
have Meta Discuss the workings and policies of this site About Us Learn syntax error in insert into statement c# more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags syntax error in insert into statement c# access Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up oledb exception syntax error in insert into statement (0x80040E14) in C# up vote 1 down vote favorite I'm having and exception in my insert into statement.But the data is inserting to the table correctly. can someone please show me the error in this code. private void btnAddNewSale_Click(object sender, EventArgs e) { string StrQuery; connection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection; for (int i = 0; i < DataGridViewAddSale.Rows.Count; i++) { StrQuery = "insert into BillItem (billNumber,storeItemNumber,numberOfItems,priceForEach,totalValue) values (" + txtBillNo.Text + ", "+ DataGridViewAddSale.Rows[i].Cells["ColCordNo"].Value + ", "+ DataGridViewAddSale.Rows[i].Cells["ColQty"].Value + ", " + DataGridViewAddSale.Rows[i].Cells["ColUnitPrice"].Value + " ," + DataGridViewAddSale.Rows[i].Cells["ColTotalValue"].Value + ");"; command.CommandText = StrQuery; command.ExecuteNonQuery(); } } Below isthe exception System.Data.OleDb.OleDbException (Ox8004OE14): Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OIeDbHResult br) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Oata.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OIeDb.OleDbCommand.ExecuteReaderlnternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQueryo at Bsystem_1 ._1 .Form2.btnAddNewSale_C
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 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 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up System.Data.OleDb.OleDbException: Syntax error in UPDATE statement up vote 0 down vote favorite I have an excel file with 2 sheets and want http://stackoverflow.com/questions/28911465/oledb-exception-syntax-error-in-insert-into-statement-0x80040e14-in-c-sharp update some values in 'Data' sheet. I use the next simple commands: var myCommand = new OleDbCommand(); var sql = "Update [Sheet2$] set Status = 'New_value' WHERE Building = 12"; var myConnection = new OleDbConnection(connectionString); myCommand.CommandText = sql; myCommand.ExecuteNonQuery(); I get error: System.Data.OleDb.OleDbException : Syntax error in UPDATE statement I have also tried this: var sql = "Update [Sheet2$] set Status = 'New_value' WHERE Building = '12'"; but with no success. What is wrong http://stackoverflow.com/questions/12814484/system-data-oledb-oledbexception-syntax-error-in-update-statement here? c# sql oledb share|improve this question asked Oct 10 '12 at 7:49 SimonD 2732314 Could you show your connection string? Do you use HDR=YES? –Steve Oct 10 '12 at 7:55 Hi, thanks for suggestion. I changed it to 'HDR=YES' and used second answer ([Status]) and it worked. –SimonD Oct 10 '12 at 9:05 But it is necessary to put the square brackets after the HDR=YES? –Steve Oct 10 '12 at 9:07 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted escape the column status var sql = "Update [Sheet2$] set [Status] = 'New_value' WHERE Building = 12"; share|improve this answer answered Oct 10 '12 at 7:52 John Woo 165k30277329 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged c# sql oledb or ask your own question. asked 4 years ago viewed 1352 times active 4 years ago Related 0UPDATE query works fine when run from Access, but raises SQL s
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 site About Us Learn more about http://stackoverflow.com/questions/23464284/oledbexception-syntax-error-in-insert-into-statement 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 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up .OleDbException Syntax error in INSERT INTO statement [closed] up vote -1 down vote syntax error favorite My software generates a query to be inserted into my Access database, but the query that comes from my code, generates a System.Data.OleDb.OleDbException, with an additional information: Syntax error in INSERT INTO statement. Debugging the code, the query generated works fine if I try to insert through Access software. I really don't know why I'm getting this exception, my query is good! Code: OleDbConnection commodityDB = null; try { syntax error in commodityDB = new OleDbConnection(connector); Console.WriteLine("Microsoft DB Connected!"); } catch (Exception ex) { Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message); return; } OleDbCommand cmder = new OleDbCommand(insert_txt,commodityDB); string insert = string.Format("INSERT INTO Comm2 (Commodity_Name, Month_Code, Year_Com, ComCode, TradeDate,Open,High,Low,Close,Vol,OI) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')", comName, comMonth, comYear, parts[0], parts[2], parts[3], parts[4], parts[5], parts[6], parts[7], parts[8]); commodityDB.Open(); cmder.CommandText = insert; cmder.ExecuteNonQuery(); myAccessConn.Close(); An example of the query generated: INSERT INTO Comm2 (Commodity_Name, Month_Code, Year_Com, ComCode, TradeDate, Open, High, Low, Close, Vol, OI) VALUES ('Australian Dollar', 'Y', '0', 'A6', '04/28/2014', '92740', '93157', '92435', '92568', '0', '0') It works fine! Not on the software though. c# sql .net share|improve this question edited May 5 '14 at 4:37 asked May 5 '14 at 3:22 Frederico Novack Amaral Pereir 123112 closed as unclear what you're asking by lpapp, gnat, Shankar Damodaran, nvoigt, Raging Bull May 5 '14 at 6:18 Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question. add a comment| 1 Answer 1 active oldest votes up vot