Simple Single Record SQL SELECT statement in C#/ASP.net
Posted on 2006-05-25
I'm looking for a simple way to do SQL Selects from a table and place the results in a set of variables in my program. It seems to me that the SQLCommand syntax is sooooooo convoluted, with the DataReader and DataSet stuff. It makes sense when your results will be multiple records, but very messy when your looking up a single value.
For instance, in PowerBuilder I could use:
LONG li_autokey = 21
WHERE systemuser.autokey = :li_autokey
USING SQLCA ;
IF SQLCA.SQLCODE <> 0 THEN
Messagebox('SQL Error ' + STRING(SQLCA.SQLCODE), 'Unable to SELECT from Systemuser. Result = ' + String(sqlca.sqlca) + ' - ' + sqlca.sqlerrtext)
In this example I would get ls_firstname set and error checking done. I know how to do it with ADO.net and DataReader, SQLCommand syntax, but they seem soooo convoluted when ALL I want is a simple SELECT to pull some values from the database. Is there any other way?