TableAdapter 的插入方法不起作用?

编程入门 行业动态 更新时间:2024-10-26 20:25:38
本文介绍了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 的插入方法不起作用?

本文发布于:2023-10-25 03:17:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   方法   TableAdapter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!