Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2007, 01:29 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default 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

 
Old January 14th, 2007, 02:18 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
DataRow.ItemArray abhi123 C# 4 June 7th, 2007 02:33 PM
Need help understanding DataRow asp_convert ADO.NET 3 March 13th, 2007 02:39 PM
Returning the Index number of an array prusila Java Basics 1 February 13th, 2007 05:54 AM
deleting a datarow sand133 VB Databases Basics 0 July 14th, 2004 07:08 AM
Returning index values from an associated array Jams30 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 October 7th, 2003 11:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.