Wednesday, March 7, 2012

Recordset with SQL and VB

Hi,

I am trying to cycle through a table and trigger an event based on some critera. I am not sure how to do it. I am a classic VBA guy, so I might be way off:

 Dim myConnectionAs SqlConnectionDim myCommandAs SqlCommand myConnection =New SqlConnection("MY SQL DATA SOURCE") myConnection.Open() myCommand =New SqlCommand("SELECT * FROM history", myConnection)Dim dr = myCommand.ExecuteReader()Dim iAs Integer = 1While dr.read() i = i + 1' HOW DO I CYCLE THROUGH THE ROWS AND ASK IF A FIELD EQUALS A VALUE ' field name = "Tail"If dr(i) = ?Then MsgBox("ok")End If End While dr.Close() myConnection.Close()
Dim myConnectionAs SqlConnection
Dim myCommandAs SqlCommand
myConnection =New SqlConnection("MY SQL DATA SOURCE")
myConnection.Open()

myCommand =New SqlCommand("SELECT * FROM history", myConnection)
Dim dr As SqlDataReader = myCommand.ExecuteReader()
While dr.read()
If dr("Tail").ToString() = somestringvalue Then'do your thang
End While
dr.Close()
myConnection.Close()

|||

Have a look at the two examples fromhere on how to loop through data.

|||

Perfect..thanks to both of you!

No comments:

Post a Comment