从DataAdapter获取数据 [英] Get data from DataAdapter

查看:125
本文介绍了从DataAdapter获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我需要从我的数据集中获取数据到数据视图(循环访问数据视图中的行)(在更改一些记录之后:插入,更新,插入)。

所以我需要一个关于这些的答案两个问题:

我可以从dataadapter获取数据到dataview吗?或者我必须从dataadapter获取数据到数据集然后从数据集到数据视图(如果可能的话)



我尝试过这样的事情:

Hello. I need to get data into dataview (to loop through the rows in the dataview) from my dataset(after making some changing some records:insert, update, insert).
So i need an answer on these two questions:
Can i get data from dataadapter into dataview ? Or i have to get data from dataadapter into dataset then from dataset to dataview(If it's possible)

I have tried something like this:

Dim strconnection As String = "Data Source=EASMAR-PC;Initial Catalog=Database Connection;Integrated Security=True;"
        _cn = New SqlConnection(strconnection)
        _cn.Open()
        cmd.Connection = _cn
        'Get the data from database into dataadapter
        _DataAdapter.SelectCommand = New SqlCommand("SELECT * FROM tblCustomer", _cn)
        'Fill the dataset from dataadapter
        _DataAdapter.Fill(_DataSet)
        Dim dt As New DataTable
        dt = _DataSet.Tables("tblCustomer")
        'dt contain nothing!!
        '_DataAdapter.Fill(dt)

        Debug.WriteLine(dt.Rows.Count.ToString)





我收到此错误:



And i am getting this error:

Object reference not set to an instance of an object.





在这一行:



On this line:

Debug.WriteLine(dt.Rows.Count.ToString)

推荐答案

您好以下链接可以帮助您

链接 [ ^ ]
Hi the following link may help you
Link[^]


我只有一张桌子。我用它的索引替换了表的名称。我不认为这是问题。

I only have one table. I replaced the name of the table by its index. I don't think it's the problem.
Dim dt As New DataTable
dt = _DataSet.Tables(0)





但它有效。

现在我从数据集中获取数据。

我检查了数据集,它包含了我的表格。

以前的错误消失了。我将继续我的想法。希望它有效。

感谢您的回复。



But it worked.
now i'm getting my data from dataset.
I checked the dataset, it contains my table.
And the previous error is gone. I am going to continue my idea. Hope it works.
Thank you for your response.


这篇关于从DataAdapter获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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