如何让 SQL Server CE TableAdapter 提交到数据库?
VS2008项目。创建本地数据库(SSCE)。使用表适配器创建数据集。将数据集和表适配器拖到表单中,以便我可以在代码中引用它。
新记录成功添加到数据集,但不会提交回数据库。没有给出任何错误或线索为什么它不起作用。
TableAdapter insert 语句是自动创建的,并且是参数化的(@p1、@p2 等),但我试图避免这些parameter.add 语句,因为我希望能够使用逐个字段的格式,而不必本质上使用parameter.add 语句在代码中重复我的数据库的架构。命令对象和 INSERT 语句工作得很好,但是您总是必须构造一个 INSERT 语句——如果它们很复杂,那就很痛苦了。我想要像使用 ADO 记录集一样简单的东西,但是在 .NET 中。
我知道更新的最后一个语句在没有参数的情况下是错误的,但正在寻找替代方法。
在没有parameter.add语句的情况下,我该怎么做才能完成以下任务?
DocsTableAdapter1.Fill(Documents1.Docs)
Debug.Print("Starting Row Count is: " & Documents1.Docs.Count.ToString)
Dim dr As DataRow = Documents1.Docs.NewRow
dr("Name") = "John Smith"
dr("Reference") = "My new reference code"
Documents1.Docs.Rows.Add(dr)
Debug.Print("New Row Count is: " & Documents1.Docs.Count.ToString)
DocsTableAdapter1.Update(Documents1.Docs)
VS2008 project. Created local database (SSCE). Created dataset with tableadapter. Dragged dataset and tableadapter to the form so I can reference it in code.
New records successfully add to the dataset but will not commit back to the database. Gives no error or clue why it won't work.
TableAdapter insert statement was created automatically and is parameterized (@p1, @p2, etc.), but I am trying to avoid those parameter.add statements as I want to be able to use a field-by-field format without having to essentially repeat the schema of my database in code with parameter.add statements. Command object and INSERT statements work fine, but then you always have to construct an INSERT statement -- a pain if they're complicated. I want something as simple as working with a ADO recordset, but in .NET.
I know the last statement with the update is wrong without the parameters, but looking for an alternative method.
What can I do to accomplish the following without parameter.add statements?
DocsTableAdapter1.Fill(Documents1.Docs)
Debug.Print("Starting Row Count is: " & Documents1.Docs.Count.ToString)
Dim dr As DataRow = Documents1.Docs.NewRow
dr("Name") = "John Smith"
dr("Reference") = "My new reference code"
Documents1.Docs.Rows.Add(dr)
Debug.Print("New Row Count is: " & Documents1.Docs.Count.ToString)
DocsTableAdapter1.Update(Documents1.Docs)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论