datareaders and primary keys

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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(objoledbreader.getordinal("nameID"))

no data returned.

I need the number of the primary key to insert in a related table as a
foreign key.
 
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.
 
Back
Top