🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.database.dotnet
4 messages
4 total messages Started by Wes Fri, 02 Feb 2007 18:44
Accessing SQL Data Delphi Syntax
#18
Author: Wes
Date: Fri, 02 Feb 2007 18:44
47 lines
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;
Re: Accessing SQL Data Delphi Syntax
#19
Author: Wayne Niddery [TeamB]
Date: Fri, 02 Feb 2007 22:07
45 lines
2511 bytes
Wes wrote:
> 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#.
>
> Here is what I have so far:
>
> var
>   connDarters : sqlConnection;

// define a reader:
    rdr: SQLDataReader;
//[...]
>        connDarters.Open;
>        sqlState.Connection := connDarters;
>        sqlState.CommandText := 'select STATE from StateTable order by
> STATE';
>        sqlState.ExecuteReader;

// Above line needs to assign the reader result:
        rdr := sqlState.ExecuteReader;

// Now you can loop the returned rows:
        while rdr.Read do
        begin
>
> // 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.

          ddlState.Items.Add(rdr.Item['state'].ToString);
        end;

The alternative is to use a data adapter instead of a command object, use 
that to Fill a Dataset, and then just bind the dropdown to the dataset.


-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"The legitimate powers of government extend to such acts only as are
injurious to others. But it does me no injury for my neighbor to say
there are twenty gods, or no God. It neither picks my pocket nor breaks
my leg." � Thomas Jefferson 
Re: Accessing SQL Data Delphi Syntax
#20
Author: Wes VanAlstyne
Date: Sat, 03 Feb 2007 12:19
13 lines
1371 bytes
Wayne,

Thanks a bunch!  That is just what I needed to get started.

I come from using Delphi 6 and still use it daily for Win32 apps.
I am comfortable with the pascal language, but I cannot seem to
get my head around some of the changes between the two versions.
I realize I am also trying to develop for a web UI which adds
another level of complexity. Can you suggest a good article or
book for individuals who are moving from an older version of Delphi
to BDS 2006?

Thanks again for your help.
Re: Accessing SQL Data Delphi Syntax
#21
Author: Wayne Niddery [TeamB]
Date: Sat, 03 Feb 2007 15:46
18 lines
1905 bytes
Wes VanAlstyne wrote:
>
> I come from using Delphi 6 and still use it daily for Win32 apps.
> I am comfortable with the pascal language, but I cannot seem to
> get my head around some of the changes between the two versions.
> I realize I am also trying to develop for a web UI which adds
> another level of complexity. Can you suggest a good article or
> book for individuals who are moving from an older version of Delphi
> to BDS 2006?

Xavier Pacheco's Delphi for .Net Developer's Guide can help a lot. There are 
of course all kinds of articles and samples around the web along with these 
newsgroups.

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"The only reason some people get lost in thought is because it's
unfamiliar territory." - Paul Fix 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads