473,473 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SqlDataSource - how get first row in SELECT?

I have a sqldatasource on a webform. How do I (in code) retrieve the value
of a particular column in the first row? Do I have to save the
sqldatasource SELECT results into a datatable and look at it that way? A
code sample would help.

Thanks!
Feb 22 '06 #1
6 3352
You have a number of solutions, here are a few:

You could use an SQL statement such as "SELECT TOP 1 [column name] FROM
[table name];" then use the ExecuteScalar Method.
http://msdn.microsoft.com/library/de...calartopic.asp

You could use an SQL statement such as "SELECT [column name] FROM
[table name];" and a DataReader to read the first row.
http://msdn.microsoft.com/library/de...ClassTopic.asp

You can fill a DataTable with the SELECT results, but you are not bound
to that single technique. Code examples can be found on the proceeding
links.

Feb 23 '06 #2
sorry. proceeding = preceding on last post.

Feb 23 '06 #3
In ASP.NET 2.0 it seems like I'm so close to already having the data with
the new SqlDataSource object. Am I missing something?

<ka*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
sorry. proceeding = preceding on last post.

Feb 23 '06 #4
Could you show some code? Maybe that would help...

Feb 23 '06 #5
That's what I want.

I have a webform with 1 item on it: An SQLDataSource that has a SELECT
statement.

I just want to retrieve (Page_Load) a field in the first record of the data
result set. Any ideas?

Again, this is 2.0...

<ka*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Could you show some code? Maybe that would help...

Feb 23 '06 #6
Do you want to return only one value after executing the query -
ExecuteScalar returns the first field in the first row
Is that what you want?
Patrick

"VB Programmer" <do**@emailme.com> wrote in message
news:eK**************@TK2MSFTNGP12.phx.gbl...
That's what I want.

I have a webform with 1 item on it: An SQLDataSource that has a SELECT
statement.

I just want to retrieve (Page_Load) a field in the first record of the
data result set. Any ideas?

Again, this is 2.0...

<ka*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Could you show some code? Maybe that would help...


Feb 23 '06 #7

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

Similar topics

5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
2
by: alain.hogue | last post by:
I have a table "tblCards" with a field "Titre" that contain french words (Hébert, Gagné, Hélène, etc....) in an database with SQLEXPRESS 2005. I have used the asp:SqlDataSource to filter the...
1
by: Henry Habermacher [MVP Access] | last post by:
Environment: VS2005, ASP.Net 2.0, SQLServer 2000, VB.Net, IIS6 I use a GridView Control which is based on a SQLDataSource. The datasource is based on a Select statement and is filtered by the...
0
by: cyberbless | last post by:
I would like to dynamically assign a Select Statment to a a SqlDataSource. Problem is the SqlDataSource.Select() Command requires a "dataSourceSelectArgument" as one of its arguments. 1. What...
7
by: | last post by:
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like the DataList and the GridView. Right now I'm using SqlDataSource as part of very quick and dirty site; I'm not looking to...
3
by: Dave | last post by:
Hi I am using .NET 2 with c# and want to retrieve a single value from my stored procedure. I currently have the following code: ...
6
by: Ken Fine | last post by:
I'm using SQLDataSource, which generates some kind of dataset, and then I attach that datasource to various data display controls such as DataList and repeater which loop through to the end of the...
2
by: Julien Sobrier | last post by:
Hello, I have 2 SqlDataSource on the same page that retrieve the same column names: <asp:SqlDataSource ID="SqlStructure" runat="server" SelectCommand="SELECT a, b FROM c WHERE d = 0 /> ...
1
by: ken | last post by:
Hi All, I try to using the dotnet control instead of code behind to create a quick solution (ASP.NET with VB.NET) by using the SqlDataSource and GridView control (with SelectCommand,...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.