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
  • 107
  • 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