473,385 Members | 1,642 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,385 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 2651
--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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.