使用 C# 更新/保存到 SQL 数据库?
我在任何地方都找不到如何在谷歌上执行此操作。 如何仅使用 C# 代码保存到 SQL DB? 是否可以? 使用向导创建数据库时默认的保存方法实际上并不保存数据库:
this.Validate();
this.studentsBindingSource.EndEdit();
this.studentsTableAdapter.Update(this.studentsDataSet.FirstClass);
I can't find how to do this on google anywhere. How do you save to a SQL DB using just C# code? Is it possible? The save method that comes default when you create a DB using the wizard dosen't actually save the DB:
this.Validate();
this.studentsBindingSource.EndEdit();
this.studentsTableAdapter.Update(this.studentsDataSet.FirstClass);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,你做得好像是正确的。
您应该检查您的表适配器并验证是否已分配更新语句。 如果您使用存储过程并且仅分配了选择存储过程,那么它将是只读的(并且不会提示您更新/插入/删除存储过程)。
It looks to me as though you are doing it correctly.
You should check your table adapter and verify that there is an update statement assigned. If you're using sprocs and only have the select sproc assigned then it'll be read only (and won't prompt you for the update/insert/delete sprocs).
连接字符串可以是多种内容,具体取决于您登录 SQL 的配置方式。
或者
如果您使用的是 Windows 身份验证,则为后者; 即使用与您登录 Windows 相同的用户帐户。
DataSource 通常是您的计算机的名称,或者如果它位于您正在使用的同一台计算机上,则可以使用 (local) 来帮助您克服困难。
Your connection string can be a few things depending on how you are configured to log into SQL.
or
The latter is if you are using Windows Authentication; i.e. using the same user account you log into windows with.
DataSource is usually your machine's name or you can use (local) to get you over the hump should it be on the same machine you are working on.