Help! When I clear and fill a dataset, it loads new data in tables(1)

S

scottin

I setup the dataset, which is the datasource for a datagrid.

When I originally fill the dataset, the data is loaded into
dataset.tables(0). (dataset.tables(0).rows.count = 8)

Then, if a row gets added to the table, I want to refresh the dataset.
When I do so, the data is loaded into dataset.tables(1).
(dataset.tables(0).rows.count = 0, dataset.tables(1).rows.count = 8)
(We can go into why the record isn't added later)

Here is the relevant code:
Sub Setup_Datagrid()
command = "SELECT columns, calculated column"
command &= " FROM table1, table2"
command &= " WHERE table1.id = '" & ID & "'"
command &= " AND table1.foreign_id = table2.id"
command &= " ORDER BY table1.id"

daMatItem.SelectCommand = New SqlClient.SqlCommand(command)
command = Nothing
daMatItem.SelectCommand.Connection = DBConnection
dsMatItem.Clear()
daMatItem.Fill(dsMatItem)
End Sub

Private Sub cmdAddRow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAddRow.Click
' This code inserted just to test.
Dim Idx As Integer = 0
Dim TotCost As Decimal = 0

dsMatItem.Clear()
daMatItem.Fill(dsMatItem)

For Idx = 0 To (dsMatItem.Tables.Count - 1)
MessageBox.Show(CStr(Idx) & ", " &
CStr(dsMatItem.Tables(Idx).Rows.Count))
Next
End Sub

After running Setup_Datagrid(), there is only 1 table with 8 rows
After clicking cmdAddRow, there are now 2 tables with 0 & 8 rows
respectively.

I have another window, doing almost the exact same thing, that works
correctly. The only difference is that I am using a dataset generated
with the data adapter wizard.
Can anyone explain what I am doing wrong?

Thanx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top