c# - 在 Visual Studio 中插入查询时出错
问题描述
我是这个领域的新手。尝试将文本框中的值插入到我的数据库表中,但出现错误
adapter.InsertCommand.ExecuteNonQuery();
谁能帮我解决这个问题?
SqlCommand command;
SqlDataAdapter adapter = new SqlDataAdapter();
String sql = "insert into NewName values('" + first_Name.Text + "','" + last_Name.Text + "','" + user.Text + "','" + email.Text + "','" + password.Text + "','" + contact.Text + "')";
command = new SqlCommand(sql,con);
adapter.InsertCommand = new SqlCommand(sql,con);
// this line here is showing the error
adapter.InsertCommand.ExecuteNonQuery();
command.Dispose();
con.Close();
解决方案
由于您的表被调用table
并且这是一个 SQL 保留字,因此您有两种选择:
- 更改您的表名。这是您应该考虑的唯一选择,但为了完整性;
引用表名:
insert into [table] values....
推荐阅读
- php - Slim 3.11 可调用解析器类型错误
- python - 如何计算每个像素值的平均值?
- python - 数独验证阻止任何移动尝试
- sql - 具有相似名称的表的多对多关系表名称
- redis - 在redis中存储30M条记录
- objective-c - 在 macOS 的 Cocoa 应用程序中,我使用 NSFileWrapper 将包保存到磁盘。如何让查找器显示我的捆绑包的正确图标?
- python - 如何从 scipy 稀疏块矩阵中取回块?
- java - 如何在java中交换2个对象的字段?
- typescript - 将可区分联合(或对象类型数组)转换为以文字属性为键的映射类型
- angular - 组件中的抽象方法实现具有未定义的依赖关系