0

Hi I have some variables assigned with values. i need to read the variables values one by one which is in a loop and assigned them to the datatable which i have created using VB.Net.. Please help me on this..

Bramenath
  • 117
  • 1
  • 4
  • 11

1 Answers1

0

You will need to create a DataRow and add these to the DataTable. If the values are in a List you can iterate through and add one at a time. If the values are in separate values you're probably best to add each in turn.

See here for more details:

MSDN How to: Add Rows to a DataTable

From this example you could use the following

Dim customerIds() As String= {"ALFKI", "QWERT", "ASDFG", "ZXCVB"}

For Each c As String In customerIds
    Dim newCustomersRow As DataRow = DataSet1.Tables("Customers").NewRow()
    newCustomersRow("CustomerID") = c
    DataSet1.Tables("Customers").Rows.Add(newCustomersRow)
Next

' Then call the data adapter update methode
myDataAdapter.Update(DataSet1)

The configuration of the DataAdapter is specific to your enviroment, but you will need a connection to the database and an InsertCommand to persist the data in the database.

Ed Harling
  • 74
  • 3
  • Ya i need to read one by one and fill the datatable in dataset. I have a dataset DtEmployee and table Employee.. So i need to fill the datatable and then need to send the completed dataset to database... – Bramenath May 22 '12 at 06:57
  • You will need a DataAdapter to push the changes to the database. – Ed Harling May 22 '12 at 07:01
  • ya i have the data adapter too.. can you pls give the piece of code to fill the table row by row by reading one by one one in a loop... – Bramenath May 22 '12 at 07:11
  • I've edited my answer and added some sample code. – Ed Harling May 23 '12 at 01:49