Displaying single record

J

Josh

This I'm sure is a silly question, but I am pulling one
field from one particular record and for the life of me
can't figure out how to display/manipulate it. Every
single tutorial or code sample relating asp.net and
database access uses a datagrid, which doesn't help me
here. Can someone please direct me to a resource that
shows the asp.net equivalent of the below code?

strSQL = "SELECT field FROM table WHERE id=1"

Set objRS = objConn.Execute(strSQL)

Response.Write objRS("field")

Thanks,

Josh
 
L

Lucas Tam

This I'm sure is a silly question, but I am pulling one
field from one particular record and for the life of me
can't figure out how to display/manipulate it. Every
single tutorial or code sample relating asp.net and
database access uses a datagrid, which doesn't help me
here. Can someone please direct me to a resource that
shows the asp.net equivalent of the below code?


Are you using a dataset or datareader?


Dataset:

label.text = ds.table(0).row(i)("item")

DataReader

label.text = dr("item")
 
T

Thomas Dodds

use commandObj.ExecuteScalar() to return the single value ...
(i'll use generic objects - you use the proper ones that correspond with
your data provider)

dim conn as new Connection(strConnString)
dim cmd as new Command()

conn.open()
cmd.connection = conn
cmd.comandtext = "select field1 from table1 where pkfield = value"
dim strField1Value as string = cstr(cmd.executeScalar())
conn.close()

the use it ....
control.Text = strField1Value
or
response.write(strField1Value)

if you aren't using ASP.NET ... this is the wrong forum ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top