I need to extract column values from one row of datareader but it did not work without using while loop.
In ADODB, I used to achieve it like this:
In ADO.NET, my coding was as follows:
I watched the contents of dr.Item(“name”) through watches window but it shows nothing at the line mregionname=dr.Item(“name”). So, I had to use a while loop to accomplish this, but there will surely be another clean approach to achieve this.
In ADODB, I used to achieve it like this:
Code:
Dim rs1 As ADODB.Recordset
Sub loadrec()
sql = "select * from Region where code=" & Request.QueryString("mcode")
rs1.Open(sql, cn)
mregionname = rs1.Fields("name").Value
mregionlocation = rs1.Fields("location").Value
End Sub
In ADO.NET, my coding was as follows:
Code:
Imports System.Data
Imports System.Data.OracleClient
Imports System.Xml
Dim cn As OracleConnection = New OracleConnection
Dim dr As OracleDataReader
Dim cmd As OracleCommand
Sub loadrec()
Dim sql = New OracleCommand
sql.Connection = cn
sql.CommandText = "select * from Region where code=" & Request.QueryString("mcode")
dr = sql.ExecuteReader
mregionname = dr.Item("name")
mregionlocation = dr.Item("location")
End Sub
I watched the contents of dr.Item(“name”) through watches window but it shows nothing at the line mregionname=dr.Item(“name”). So, I had to use a while loop to accomplish this, but there will surely be another clean approach to achieve this.
Code:
Sub loadrec()
Dim sql = New OracleCommand
sql.Connection = cn
sql.CommandText = "select * from Region where code=" & Request.QueryString("mcode")
dr = sql.ExecuteReader
While dr.Read
mregionname = dr.Item("name")
mregionlocation = dr.Item("location")
End While
End Sub