使用 C# 更新/保存到 SQL 数据库?

发布于 2024-07-17 08:05:02 字数 238 浏览 2 评论 0原文

我在任何地方都找不到如何在谷歌上执行此操作。 如何仅使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月流歌 2024-07-24 08:05:02

在我看来,你做得好像是正确的。

您应该检查您的表适配器并验证是否已分配更新语句。 如果您使用存储过程并且仅分配了选择存储过程,那么它将是只读的(并且不会提示您更新/插入/删除存储过程)。

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).

-柠檬树下少年和吉他 2024-07-24 08:05:02

连接字符串可以是多种内容,具体取决于您登录 SQL 的配置方式。

Data Source=ServerName;Initial Catalog=DatabaseName;User Id=myUsername;Password=myPassword;

或者

Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=SSPI;

如果您使用的是 Windows 身份验证,则为后者; 即使用与您登录 Windows 相同的用户帐户。

DataSource 通常是您的计算机的名称,或者如果它位于您正在使用的同一台计算机上,则可以使用 (local) 来帮助您克服困难。

Your connection string can be a few things depending on how you are configured to log into SQL.

Data Source=ServerName;Initial Catalog=DatabaseName;User Id=myUsername;Password=myPassword;

or

Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=SSPI;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文