问题描述
我在我的 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 的插入方法不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!