reading from a table

Joined
Apr 6, 2005
Messages
6
Programming Experience
Beginner
i am trying to get my vbnet program to read from the table,i have found a way to read colmuns but how do i read from rows.

i.e.
VB.NET:
 TextBox1.Text = dr(0)
				TextBox2.Text = dr(1)
				TextBox3.Text = dr(2)

this will read across the first row but how do i get it to go to the next row as well ?

advice
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,458
Location
Sydney, Australia
Programming Experience
10+
"dt" is a DataTable object, but that is assuming that your "dr" is a DataRow and not a DataReader. If you Fill a DataTable, either stand-alone or in a DataSet using a DataAdapter, use mzim's method to read each row from the table. If you ExecuteReader on a Command, call Read on the DataReader to read each row.
 

DeBiese

New member
Joined
Apr 24, 2005
Messages
4
Programming Experience
Beginner
A possibility to go through your datarows:
VB.NET:
Dim con As New SqlConnection(<connectionstring>)
Dim myDapt As New SqlDataAdapter
Dim mySet As New DataSet
Dim cmdSelect As New SqlCommand
Dim bm As BindingManagerBase
  
With myDapt
.SelectCommand = cmdSelect
End With
 
With cmdSelect
.CommandType = CommandType.Text
.CommandText = "Select * From <table>"
.Connection = con
End With
 
myDapt.Fill(mySet, <tablename as string>)
bm = Me.BindingContext(mySet, <tablename as string>)
TextBox1.DataBindings.Add(New Binding("Text", mySet, <columnname as string> ))
TextBox2.DataBindings.Add(New Binding("Text", mySet, <columnname as string>))
TextBox3.DataBindings.Add(New Binding("Text", mySet, <columnname as string>))

Now that this is done, you can go through the datarows by making some buttons:

VB.NET:
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click

With bm
  If .Position <> 0 Then
	.Position -= 1
  End If
End With
End Sub 

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

With bm
  If .Position <> .Count - 1 Then
	.Position += 1
  End If
End With
End Sub


 
Top Bottom