插入的TableAdapter不工作的方法是什么? [英] Insert method of TableAdapter not working?

查看:109
本文介绍了插入的TableAdapter不工作的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ADO.NET在我的C#项目。在我的表单我加了一个SourceBinding元素从我的VS2010的工具箱。我设置连接到我的数据集的表。它为我创造一个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(行)来把它的数据集。

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(数据集)来的新行发送到数据库中。

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不工作的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆