[英]Syntax error (missing operator) in query expression, Oledb UPDATE Statement
I'm a beginner at c# and I've tried looking through many posts to try and resolve my problem but I haven't had any luck, so I thought I may as well create a post to ask for your help. 我是c#的初学者,我尝试遍历许多帖子以尝试解决我的问题,但是我没有任何运气,因此我认为我最好还是创建一个帖子以寻求您的帮助。 Basically,I'm trying to update an excel file with some extra info, but the problem is every-time I run the source code I keep getting this error:
基本上,我试图用一些额外的信息来更新excel文件,但是问题是每次我运行源代码时,我都会不断收到此错误:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll System.Data.dll中发生了类型为'System.Data.OleDb.OleDbException'的未处理异常
Additional information: Syntax error (missing operator) in query expression 'Wireless Stereo Headphone (TAK) (damaged)'. 附加信息:查询表达式“无线立体声耳机(TAK)(损坏)”中的语法错误(缺少运算符)。
I've tried a lot of ways to fix it including using an INSERT statement instead of the UPDATE statement but nothing seems to work. 我尝试了很多方法来修复它,包括使用INSERT语句而不是UPDATE语句,但是似乎没有任何效果。
Thanks again for the Help =). 再次感谢您的帮助=)。
int m_intRecipientESMID = Convert.ToInt32(m_recipientESMID);
//Converting Row integer to string
string m_excelRowCoordinateLoanItemTrackerStr = m_excelRowCoordinateLoanItemTracker.ToString();
//Creating a connection directory to access the Excel "LoanItemTracker" file
string m_pathSourceExcelLoanItemTrackerNOHDR = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBoxExcelLoanItemTrackerLocation.Text + @";Extended Properties=""Excel 8.0; HDR=NO;ImportMixedTypes=Text;TypeGuessRows=0""";
OleDbConnection m_pathConnectionExcelLoanItemTrackerNOHDR = new OleDbConnection(m_pathSourceExcelLoanItemTrackerNOHDR);
m_pathConnectionExcelLoanItemTrackerNOHDR.Open(); //Open Excel File LoanItemTracker.xlsx to conduct Write/Update process
string m_scannedItemName2 = "Wireless Stereo Headphone (TAK) (damaged)";
// write the loaned item name into the Excel Spread sheet "LoanItemTracker.xls"
string m_excelRowColumnLoanItemNameCoord = String.Concat(m_excelColumnCoordinateLoanItemNameLoanItemTracker, m_excelRowCoordinateLoanItemTrackerStr);
string m_LoanItemNameWriteCommand = String.Format("UPDATE [Sheet1${0}:{0}] SET F1={1}", m_excelRowColumnLoanItemNameCoord, m_scannedItemName2);
OleDbCommand m_LoanItemTrackerCommandWrite = new OleDbCommand(m_LoanItemNameWriteCommand, m_pathConnectionExcelLoanItemTrackerNOHDR);
m_LoanItemTrackerCommandWrite.ExecuteNonQuery();
m_pathConnectionExcelLoanItemTrackerNOHDR.Close();
You have to put quotes around the text: 您必须在文本两边加上引号:
String.Format("UPDATE [Sheet1${0}:{0}] SET F1='{1}'", m_excelRowColumnLoanItemNameCoord, m_scannedItemName2);
I put them before and after {1}
. 我将它们放在
{1}
之前和之后。 Also, it is preferred to use parameterized queries. 另外,最好使用参数化查询。 You won't need quotes then too.
然后,您也不需要引号。
检查它: UPDATE [Sheet1${0}:{0}] SET F1='{1}'
也许您忘记了引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.