back up codes

always have a backup of your code

Archive for the tag “datareader”

read at two datareader on while loop

The following code will read two datareader on a while loop:


mycommand = New Data.SqlClient.SqlCommand("SELECT * FROM MY_TABLE", myconnection)
myreader = mycommand.ExecuteReader()
While myreader.Read()
myothercommand = New Data.SqlClient.SqlCommand("SELECT * FROM MY_VIEW", myotherconnection)
myotherreader = myothercommand.ExecuteReader()
If myotherreader.Read Then
(do something here if it exist)
Else
(do something here if it doesn't exist)
End If
myotherreader.Close()
End While
myreader.Close()

while loop in reading datareader

The following code is a sample on how to read a datareader if more than one rows are retrieved.

The following code can be inserted in any event, which computes the total for the data retreived:

command = New Data.SqlClient.SqlCommand("SELECT * FROM MY_TABLE", connection)
reader = command.ExecuteReader()
While reader.Read
Dim myAmount As Decimal = reader("THE_AMOUNT")
totalamount = totalamount + myAmount
End While
reader.Close()

Post Navigation

Follow

Get every new post delivered to your Inbox.