c# - 在 Excel 工作表中插入数据时 Insert into 语句中出现语法错误

标签 c# asp.net excel

我正在运行时在 Windows 窗体中导入 Excel 工作表,通过窗体向其中添加一些数据。当我将该数据插入回来时,它会给出:

syntax error in insert into statement

这是我正在使用的查询:

string qry = string.Format("Insert into [Sheet1$] (username,password) values('"+uname+"','"+pwd+"')");

最佳答案

试试这个,即向列添加 [] :

string qry = string.Format("Insert into [Sheet1$] ([username],[password]) values('"+uname+"','"+pwd+"')");

也可以尝试不使用string.Format()

关于c# - 在 Excel 工作表中插入数据时 Insert into 语句中出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13945343/

相关文章:

c# - C#中如何获取对象的值

c# - 在 DevExpress 中以编程方式计算 GroupSummary 值

asp.net - 缺少字符串值的右引号

excel - 使用基于另一个条件的现有公式输出覆盖单元格数据

c# - 如何在 C# 中读取制表符分隔的 Excel 文件中的列?

python - 使用 Pandas 在python中循环遍历多个excel文件

c# - WCF[互联网场景]。传输\序列化(de)数据的最快方式

c# - 在磁盘上创建虚拟文件

c# - 需要帮助使用 for 循环递增 1。每次只加1

c# - Asp.Net ViewState 性能