TableAdapter 的插入方法不起作用?

Insert method of TableAdapter not working?(TableAdapter 的插入方法不起作用?)
本文介绍了TableAdapter 的插入方法不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 C# 项目中使用 ADO.NET.在我的表单中,我从 VS2010 的工具箱中添加了一个 SourceBinding 元素.我将连接设置为我的数据集表.它会自动为我创建一个 DataAdapter.

I'm using ADO.NET in my C# project. In my form I added a SourceBinding element from my toolbox in VS2010. I set the connection to the table of my dataset. It creates a DataAdapter automaticly for my.

我要插入一条记录,所以我调用DataAdapter 的Insert() 方法.但是当我查看我的数据库数据时,它没有任何新记录...

I want to insert a record, so I call the Insert() method of the DataAdapter. But when I view my database data, it doesn't have any new records...

orderID = this.orderTableAdapter.Insert("", "", 
                (int)OrderStatus.IN_CONSTRUCTION, DateTime.Now);

还是需要用SqlCommand手动插入???

Or do I need to insert it manually with the SqlCommand???

推荐答案

表适配器设计为与数据集一起使用,以帮助您使用该数据集将数据输入和输出数据库.

The table adapters are designed to be used with a dataset, to help you get data in and out of the DB using this dataset.

想法是您可以使用 Dataset.NewYourTableNameRow() 为您的数据集创建一个新行,然后填充其字段,然后调用 DataSet.AddYourTableNameRow(row) 将其放入数据集中.

Idea is that you can use the Dataset.NewYourTableNameRow() to create a new row for your dataset, then populate its fields and then call DataSet.AddYourTableNameRow(row) to put it in the dataset.

现在您可以orderTableAdapter.update(DataSet) 将该新行传输到数据库中.

Now you can orderTableAdapter.update(DataSet) to transmit that new row into the database.

要删除或更新一行,您可以先将其选择到数据集中,对对象执行更改,然后调用相应表适配器上的 .update(ds) 将其发送回.

To delete or update a row, you would select it first into your dataset, perform a change to the object, then call the .update(ds) on the appropriate table adapter to send it back down.

这篇关于TableAdapter 的插入方法不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)