datareaders and primary keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bindurajeesh

    #1

    datareaders and primary keys

    How do I capture the data in a primary key?

    strsql="select nameID,fname from tblname where fname = '" & txtFname.text &
    "' and lname = '" & txtlname.text & "'"

    objOleDBCommand .CommandText = strsql
    objoledbreader = objOleDbCommand .ExecuteReader( )
    intname = objoledbreader. item("nameID")

    error "No data exists for the row/column
    I go to the tblname on sql server and there is data in table when above
    query is run with appropriate names.

    I have tried intname =
    objoledbreader. getstring(objol edbreader.getor dinal("nameID") )

    no data returned.

    I need the number of the primary key to insert in a related table as a
    foreign key.
  • Marina Levit [MVP]

    #2
    Re: datareaders and primary keys

    When you call ExecuteReader, the current row pointer is positioned *before*
    the first row.

    You have to call the .Read method, which tells you if it was able to move to
    the next row. The first time you call it, it would attempt to position on
    the first row if the query returned any rows.

    "bindurajee sh" <bindurajeesh@d iscussions.micr osoft.comwrote in message
    news:51829793-FCB1-4AAE-B6ED-A0A10577014F@mi crosoft.com...
    How do I capture the data in a primary key?
    >
    strsql="select nameID,fname from tblname where fname = '" & txtFname.text
    &
    "' and lname = '" & txtlname.text & "'"
    >
    objOleDBCommand .CommandText = strsql
    objoledbreader = objOleDbCommand .ExecuteReader( )
    intname = objoledbreader. item("nameID")
    >
    error "No data exists for the row/column
    I go to the tblname on sql server and there is data in table when above
    query is run with appropriate names.
    >
    I have tried intname =
    objoledbreader. getstring(objol edbreader.getor dinal("nameID") )
    >
    no data returned.
    >
    I need the number of the primary key to insert in a related table as a
    foreign key.

    Comment

    Working...