473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Return one record from database

Hi - I want to query a database to return just one record:

..select id, parentid, question, answer from tblquestions where id =
@id)..

read the fields returned from that record into variables:

id=rs("id").value
parentid=rs(parentid").value
...
..

..and close the connection.

I don't want to populate datasets etc - I've heard about the
executescalar and executeonerecordonly(or similar) - but haven't seen
any examples - can anyone please procvide an example of this for me?

Many thanks for any help,
Mark Tait
ma**@fixitks.co.uk
www.fixitks.co.uk

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #1
3 2652
--sql 2000
select top 1 * from tablename
--sql 7
set rowcount 1
select * from tablename

executescalar returns the first column of the first row...

"Mark Tait" <ma**@fixitks.co.uk> wrote in message
news:uC**************@TK2MSFTNGP11.phx.gbl...
Hi - I want to query a database to return just one record:

.select id, parentid, question, answer from tblquestions where id =
@id)..

read the fields returned from that record into variables:

id=rs("id").value
parentid=rs(parentid").value
..
.

.and close the connection.

I don't want to populate datasets etc - I've heard about the
executescalar and executeonerecordonly(or similar) - but haven't seen
any examples - can anyone please procvide an example of this for me?

Many thanks for any help,
Mark Tait
ma**@fixitks.co.uk
www.fixitks.co.uk

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #2
Hi - thankyou, don't think I made myself clear though.

I know about sql statements (top, limit etc), it's ASP.Net I'm getting
to grips with.

My sql statement knows the ID to select - I just don't know how to do
this efficiently from ASP.Net without getting the info into a dataset
first, and then binding it to something.

All I want is to select a record, and read the fields values in that
record into some variables, which I can then manipulate elsewhere. Can
I do this without having to read a dataset and bind it?

Thanks,

Mark Tait
ma**@fixitks.co.uk
www.fixitks.co.uk

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
In article <ui**************@TK2MSFTNGP09.phx.gbl>, ma**@fixitks.co.uk
says...
All I want is to select a record, and read the fields values in that
record into some variables, which I can then manipulate elsewhere. Can
I do this without having to read a dataset and bind it?


string strCon = "Your connection string"
SqlDataReader dr;

dr = SqlHelper.ExecuteReader(strCon, CommandType.Text, "select blah blah
blah")

dr.Read()
dr.GetString(0)
....
dr.GetString(n)
There you go. Hope that helps. The GetStrings return the fields.

-- Rick
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Adrian Parker | last post by:
Hi. I would like to query a database, given several where clauses to refine my search, and return the value of one single field in the database. eg: I have a table that lists teachers. Their...
6
by: Tony Stoker | last post by:
I have a .Net web app that adds a record to a SQL database. After the user adds their record I want to have a link that will link them to their new record! The recordID is a AutoNumber in the...
17
by: Gabriel Mejía | last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may intermittently return empty recordsets on queries that should be returning valid results. At the time the problem...
19
by: Barry Edmund Wright | last post by:
This simple stupid thing has me stumped! The cursor is on a record in a datasheet. How do I select that record (highlight) like I would if I clicked on the Record Selector using VBA. Regards....
20
by: MS | last post by:
Access 97 I want to requery the data being displayed on a form, then I want to return to the record I was in. Why doesn't this code work? Private Sub CmdRefsh_Click()
6
by: Hardy Wang | last post by:
Hi all, I have the following codes, but SCOPE_IDENTITY() just returns NULL to me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works fine!! Since I have a trigger on the...
1
by: David | last post by:
Hi, I have a problem with returning a value from an external function..... My asp page is basically a list taken from a database. A date record is written from the DB, then all the...
0
by: rajg78 | last post by:
Hi All, First time I am posting, so please forgive me if I miss out any information while asking you my question. I have a .net web app that I am building in 2.0 framework. I have a code-behind...
2
by: jennk | last post by:
i am working in Access 97, our database tables are linked from ODBCsqlsvr (not even sure what that means). i have a table where each record has a unique customer and their order information. there...
1
by: nur123 | last post by:
Thanks in advance who will look at it. I have been encountering an issue which I can’t find a way out of it. What my pgm does: It (java codes) reads oracle table data and creates flat text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.