1

I created a table adapter for a stored procedure I have, which returns a row from a table. After adding it to the dataset, I try to loop through the row count of this table to retrieve the data but it keeps returning no rows. If I try to preview the data in the dataset designer, i get the row normally but when i try it in code i get nothing

For intI As Integer = 0 To Me.Ds1.SP_Get_Data_Communication_Parameters.Rows.Count - 1

            Dim IP As String = Ds1.SP_Get_Data_Communication_Parameters.Rows(intI)("Remote_IP_address")

        Next
Eagz
  • 21
  • 4

1 Answers1

2

A tableadapter is a device that moves data in either direction between a database and a datatable.

A datatable is part of a dataset (a dataset is a collection of datatable)., and is a client side representation of (some or all) of a database table.

To work with database data you use a tableadapter to transfer it from the database table to the datatable. You work with it, maybe edit it and maybe save it back to the database

From what you've described it sounds like you're not actually using a tableadapter to fill the datatable before inspecting it for data. The dataset designer is just a visual representation of the tableadapter and associated datatable classes; it doesn't mean that the database data is automatically available in your program

You'll need to have a code like:

Dim ta As New YourDatasetNameTableAdapters.SP_Get_Data_Communication_ParametersTableAdapter()

ta.Fill(Me.Ds1.SP_Get_Data_Communication_Parameters, any, parameters, the, sproc, needs, here)

Then you can look through the datatable and see the data the TA downloaded


Edit footnote:

If you make changes to the rows, like

For Each ro in Ds1.SP_Get_Data_Communication_Parameters 
  ro.FirstName = "John"
Next ro

Then you can send the changes back to the db using the Update method of the table adapter

at.Update(Ds1.SP_Get_Data_Communication_Parameters)

Update will run all different kinds of query, not just UPDATE. Newly added rows will be INSERT. Deleted rows will be DELETEd. Microsoft should really have called it SaveChanges

Caius Jard
  • 72,509
  • 5
  • 49
  • 80