本文介绍了如何使用C#将insert插入到语句中以进行访问2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个通用方法,我可以将SQL语句作为参数发送,并在我的Access数据库中执行语句。写了一个当我正在做的就是从数据库中获取信息时有效,但我似乎无法让一个人将信息放入数据库。
SQL = Insert into [Category] (CategoryDescription)值('Pizza')
我得到一个操作必须使用可更新的查询错误
我尝试过:
I am trying to write a generic method where I can send a SQL statement as a parameter and have the statement execute in my Access Database. Have written one that works when all I'm doing is getting information from the database, but I can't seem to get one working that puts information into the database.
SQL = Insert Into [Category] (CategoryDescription) values('Pizza')
And I am getting a "Operation must use an updateable query" error
What I have tried:
public void ExecuteAction(string SQL)
{
OpenDatabase();
OleDbCommand myAccessCommand = new OleDbCommand(SQL, Conn);
myAccessCommand.ExecuteNonQuery();
CloseDatabase();
}
但这不起作用。
But this doesn't work.
推荐答案
Insert Into [Category] (CategoryDescription) Values('" + txtNewCategory.Text + "')"
这篇关于如何使用C#将insert插入到语句中以进行访问2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!