Click here to Skip to main content
15,040,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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:
VB
Object reference not set to an instance of an object.


On this line:
VB
Debug.WriteLine(dt.Rows.Count.ToString)
Posted
Comments
Pheonyx 3-Jan-14 6:00am
   
After "_DataAdapter.Fill(_DataSet)" how many tables are present in _DataSet.Tables ?
Sibasisjena 3-Jan-14 6:04am
   
There may be 2 cases
1.The table tblCustomer is not there in dataset
2.There is no table in the dataset

Please check the dataset while debugging and let me know.
Thanks,
Sibasis

Hi the following link may help you
Link[^]
   
Comments
[no name] 3-Jan-14 6:23am
   
Thank you :)
helpful link
Sibasisjena 3-Jan-14 6:31am
   
Please like my solution :)
I only have one table. I replaced the name of the table by its index. I don't think it's the problem.
VB
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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900