|
Subject:
|
Why is DataRow returning 1 more index
|
|
Posted By:
|
rsearing
|
Post Date:
|
1/14/2007 12:29:50 AM
|
I have written the following function to return an ID from a table I have. (I have to admit, I am not used to retrieving data myself with Rows and such)...when I debug, and look at "mID" it is always one more (valuewise) than the value in the table. So, if the ID of the table is 75, the value of mID is 76---why the difference of 1?
Public Shared Function GetMemberID(ByVal uName As String) As Integer Dim knightsDBConn As New SqlConnection(conString) Dim mID As Integer Dim myRow As DataRow Dim sqlString As String = "SELECT memberID FROM members WHERE userName = '" & uName & "'" Dim sqlCmd As New SqlCommand(sqlString, knightsDBConn) knightsDBConn.Open() Dim myTable As New DataTable
Dim memberSQLDR As SqlDataReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection) myTable.Load(memberSQLDR) myRow = myTable.NewRow mID = myRow("memberID") Return mID End Function
|
|
Reply By:
|
rsearing
|
Reply Date:
|
1/14/2007 1:18:08 AM
|
Ok--I figured it out--but not sure why I got 76 the first time.
I changed the line:
myRow = myTable.NewRow
to
myRow=myTable.Rows(0)
(I got NewRow from some example somewhere).
-Rob
|
|