Why is DataRow returning 1 more index
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.CloseConnecti on)
myTable.Load(memberSQLDR)
myRow = myTable.NewRow
mID = myRow("memberID")
Return mID
End Function
|