Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I navigate through Records in Database?

Status
Not open for further replies.

jgaylord

IS-IT--Management
Apr 17, 2006
11
US
I want to use a Select * SQL statement....
then put the first record into textbox fields... How?
Perform some calculations....
Then move to the next record. How?

Thanks for any help...
 
Basic Structure I use for this scenario:

You need Imports System.Data.SQLClient

Code:
Dim con As New SQLConnection(connectionstring)
Dim com As New SQLCommand("SELECT * FROM myTable", con)
com.CommandType = CommandType.Text
con.Open()
Dim dr As SQLDataReader = com.ExecuteReader
While dr.Read
    'Your logic goes here.  This is the "loop".  Whatever
    'you put here will be executed for each record returned
    'by the SELECT statement
End While
dr.Close()
com.Dispose()
con.Close()

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Thanks... I understand how it will move through the records now. But how do I place the values into the textboxes?

Field1 = txtField1.text
 
try this in the area mstrmage said to put you logic


me.mytextbox.text = dr("mycolumn")
 
And to further Dashleys correct statement, if you have OPTION EXPLICIT ON and OPTION STRICT ON, you will also need to include a .ToString, such as:

me.mytextbox.text = dr("mycolumn").ToString

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
OK Sorry I need so much help......
This was working... Now its not.... I dont understand.
I get this no data in the row error...

Sorry about multiple post I am learning the whole forum edicate...
Code:
Dim SelectCmd2 As System.Data.OleDb.OleDbCommand
            SelectCmd2 = New System.Data.OleDb.OleDbCommand("Select * from Xnet", dbconnection)
            Dim dbreader2 As System.Data.OleDb.OleDbDataReader
            dbreader2 = SelectCmd2.ExecuteReader
            Do While doneFlag <> 1
                Do While LeaveLoop = False
                    Me.txtXnetAni.Text = dbreader2("ANI")
                    Me.txtXnetDate.Text = dbreader2("Date")
                    Me.txtXnetAmount.Text = dbreader2("Xnet Amount")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top