Article View: borland.public.delphi.database.dotnet
Article #18Accessing SQL Data Delphi Syntax
From: Wes
Date: Fri, 02 Feb 2007 18:44
Date: Fri, 02 Feb 2007 18:44
47 lines
2562 bytes
2562 bytes
I am trying to access data from a SQL database and I cannot figure out the
syntax for it using BDS 2006 in a .NET aspx. I am using the Delphi style
syntax, not C#.
On my Design tab I have place a ASP DropDownList control and called it
ddlState.
I have placeed a System.Data.SqlClient.SqlCommand and added a simple sql
select statement to it in code.
I have successfully created a connection to the database using
sqlConnection.
I believe I have correctly opened up the sqlState using the
sqlState.ExecuteReader command.
Now all I want to do is loop through the data to add dropdown elements to my
ddlState control.
I understand there may be two ways to do this. One is to assign a DataSource
to the ddlState control, and the other is to loop thru the retrieved data
and use the Items.Add property.
Could someone get me over this concept by showing me a simple code snipet?
Thanks, Wes
Here is what I have so far:
var
connDarters : sqlConnection;
begin
if ( not Page.IsPostBack) then begin
connDarters := sqlConnection.Create;
connDarters.ConnectionString := '<my connection string to the sql
database in here>';
connDarters.Open;
sqlState.Connection := connDarters;
sqlState.CommandText := 'select STATE from StateTable order by
STATE';
sqlState.ExecuteReader;
// This is whare further code most likely should be placed to fill in the
drop-down
ddlState.Items.Add('TX'); // This was just a test to see if some
data showed up in the drop-down. It worked.
end;
end;
Technical Details
Message-ID:
<45c38651$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.net!prodigy.net!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1effe6,37f179b7946f073,start X-Google-Attributes: gid1effe6,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Wes" <wesv@wintech-inc.com> From: "Wes" <wesv@wintech-inc.com> Newsgroups: borland.public.delphi.database.dotnet Subject: Accessing SQL Data Delphi Syntax Date: Fri, 2 Feb 2007 13:44:21 -0500 Lines: 49 Organization: Wintech X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 70.62.103.188 Message-ID: <45c38651$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1170441809 70.62.103.188 (2 Feb 2007 10:43:29 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.net!prodigy.net!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail