Parag’s Den

Dedicated to my adored friends…..

Asp.Net (How to loop through a DataTable?)

Posted by paragdongre on November 6, 2007

The following example tells you how to loop through a DataTable. We can relate the DataTable to the RecordSet in Classic ASP (Active Server Pages).

Dim adapter As SqlDataAdapter
Dim ds As DataSet
Dim ctr As Integer

     adapter = New SqlDataAdapter(“YourSQLStatement”, “YourConnectionString”)
     ds = New DataSet()
     adapter.Fill(ds, “myTable”)

     If ds.Tables(0).Rows.Count > 0 Then
          For ctr = 0 To ds.Tables(“entries”).Rows.Count – 1
     End If

Catch exc As SqlException
     Response.Write(“SQL Error Occured: ” & exc.ToString)

Catch exc As Exception
     Response.Write(“Error Occured: ” & exc.ToString)

     adapter = Nothing
     ds = Nothing

End Try


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: