Article View: borland.public.delphi.database.dotnet
Article #682Re: D8 MS-SQL
From: Stewart Basterash
Date: Sat, 23 Oct 2004 04:06
Date: Sat, 23 Oct 2004 04:06
113 lines
4926 bytes
4926 bytes
OK... the other message was my rant... GRRRRR!
Here is your example... although it is slightly differnet then what you are
asking for... I purposly made this example easy so that you understand the
concept... you can integrate a grid later... it will take some thought and
investigation, but this works and is an easy concept...
1. Create a new web form...
2. Add two "Web Controls"... Listboxes...
3. Add the code listed to the TMainForm.Page_Load procedure. {not doing this
in ide so watch for typo's and errors}
4. In the IDE Object Inspector for Listbox1... set the DataTextField to the
fieldname returned from display getListBoxJunk1 (fieldnameforlist).
5. In the IDE Object Inspector for Listbox1... set the DataValueField to the
fieldname for lookup operations (fieldindexidentity) {these should be acutal
fields returned from your query statement}
6. Follow the same steps for ListBox2... Set the two fields that match the
DataTextField, and the DataValueField to match what is being returned in the
getListBox2junk function...
7. finally... for Listbox1... in the IDE Object Inspector... set the
AutoPostBack behavior to TRUE... what this does is kick your form back to
the server... now all you have to do is place the following code in the
SelectedIndexChanged Event... (onclick for you old D6-D7 guys)...
const:
cnxstr =
'Server=myserver;Database=mysqldb;user=joeuser;password=bigsecret';
procedure TMainForm.Page_Load(sender: System.Object; e: System.EventArgs);
begin
// TODO: Put user code to initialize the page here
if not ispostback
then begin
Listbox1.DataSource := getListBox1Junk; {this is a function
call I put in another unit with all my query junk}
Listbox1.DataBind;
end
else begin
end;
end;
procedure TMainForm.ListBox1_SelectedIndexChanged(sender: System.Object; e:
System.EventArgs);
begin
ListBox2.DataSource := getListBox2Junk(ListBox1.SelectedValue);
ListBox2..DataBind;
end
function getListBox1Junk: Dataset; {returns a Dataset... which is what the
listbox datasource is looking for}
var
adp: SqlDataAdapter;
s: string;
begin
{I'm returning two fields... one is the identity column of the table... the
other is my display item}
s := s + 'select fieldindexidentity, fieldnameforlist from tablename ';
s := s + 'order by fieldnameforlist';
adp := SqlDataAdapter.Create(s, cnxstr);
Result := DataSet.Create;
adp.Fill(Result);
adp.Dispose;
end;
function getListBox2Junk(value: integer): Dataset; {returns a Dataset... but
I pass in the lookup id... KEY}
var
adp: SqlDataAdapter;
s: string;
begin
{again I'm returning two fields... one is the identity column of the
table... the other is my display item}
s := s + 'select fieldindex, fieldname from tablename ';
s := s + 'Where fieldindex=' + Convert.ToString(value);
s := s + 'order by fieldname';
adp := SqlDataAdapter.Create(s, cnxstr);
Result := DataSet.Create;
adp.Fill(Result);
adp.Dispose;
end;
"DA Brookes" <david_dot_brookes_at_interserveprojects.com> wrote in message
news:4177b896$1@newsgroups.borland.com...
> Hi
> I've had D8 for 10 months now. Each time I take a look at it, I end up
> going
> back to D6.
>
> I am trying to create a very simple web form. It has two databases, a
> DBwebdropdownlist and a dbwebgrid.
>
> All I want to do is select a value from the drop down list (database1)
> which
> then selects the required fields (from a second database) in the grid.
>
> In D6 / D7 this is easy, I enter code to run a query in "onchange (etc)"
> in
> D8, I'm clueless.
>
> This shouldn't be rocket science and I feel foolish having to ask.
>
> Perhaps someone could provide an example, or point me to a site that
> offers
> examples ?
>
> Regards
> Dave
>
>
Technical Details
Message-ID:
<4179d9d2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!diablo.voicenet.com!38.119.100.83.MISMATCH!news-out1.nntp.be!propagator2-sterling!news-in.nuthinbutnews.com!in.nntp.be!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4177b896$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1effe6,f662505e75651efa X-Google-Attributes: gid1effe6,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Stewart Basterash" <stewartbash@hotmail.com> Newsgroups: borland.public.delphi.database.dotnet References: <4177b896$1@newsgroups.borland.com> Subject: Re: D8 MS-SQL Date: Fri, 22 Oct 2004 23:06:38 -0500 Lines: 115 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 65.42.181.33 Message-ID: <4179d9d2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1098504658 65.42.181.33 (22 Oct 2004 21:10:58 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!diablo.voicenet.com!38.119.100.83.MISMATCH!news-out1.nntp.be!propagator2-sterling!news-in.nuthinbutnews.com!in.nntp.be!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail