Two SQL Statements in Page_Load (Advanced)

S

Sparky Arbuckle

First and foremost, is it possible to execute two SQL statements that
grab different data out of the same database in the same Page_Load
subroutine?

I am building a music store and want to do a SQL for ASIN, Release
Date, Number of Disks, Price, etc... I have done this successfully.

The next SQL I am constructing is going to be for the track numbers,
names, and url for audio clips.

I guess my question is this: How would I go about successfully creating
two different SQL statements and referencing them in two different
datalists? I have successfully created and bound the first SQL to a
DataList and am running in to problems with the second one.

<!-- SQL statement for TrackListing [START] -->

Dim strSQLTracks as string = "SELECT ASIN, TrackNum, TrackName,
SampleURL FROM tblTracks WHERE ASIN ='" & strASIN & "';" & _
"FROM tblDescription WHERE ASIN = '" & strASIN & "';"

<!-- SQL statement for TrackListing [END] -->
 
O

Olle de Zwart

Sparky said:
First and foremost, is it possible to execute two SQL statements that
grab different data out of the same database in the same Page_Load
subroutine?

I am building a music store and want to do a SQL for ASIN, Release
Date, Number of Disks, Price, etc... I have done this successfully.

The next SQL I am constructing is going to be for the track numbers,
names, and url for audio clips.

I guess my question is this: How would I go about successfully creating
two different SQL statements and referencing them in two different
datalists? I have successfully created and bound the first SQL to a
DataList and am running in to problems with the second one.

<!-- SQL statement for TrackListing [START] -->

Dim strSQLTracks as string = "SELECT ASIN, TrackNum, TrackName,
SampleURL FROM tblTracks WHERE ASIN ='" & strASIN & "';" & _
"FROM tblDescription WHERE ASIN = '" & strASIN & "';"

<!-- SQL statement for TrackListing [END] -->

Yes it is possible.

You create a seccond datalist and bind that that to the result of a
second SqlCommand instance.

Next time please be more specific in the problem you are running into,
or the code that you are using.


On another note think about using parameterized queries, like stored
procedures to be allot less susceptible to SQL injection attacks. For
more information on that check out:
http://msdn.microsoft.com/msdnmag/issues/04/09/SQLInjection/default.aspx
 
S

Sparky Arbuckle

Dim strASIN
strASIN = Request.QueryString("ASIN")

Dim objConn as new
OLEDBConnection(ConfigurationSettings.AppSettings("StrConnection"))

Dim strSQL as string = "SELECT ASIN, strTitle, strArtist, decPrice,
strLabel, intNumberDisks, dtReleaseDate, strReview, strImageDir " & _
"FROM tblDescription WHERE ASIN = '" & strASIN & "';"

Dim strSQLTracks as string = "SELECT ASIN, TrackNum, TrackName,
SampleURL FROM tblTracks WHERE ASIN ='" & strASIN & "';" & _
"FROM tblDescription WHERE ASIN = '" & strASIN & "';"

Dim objDataReader as OLEDBDataReader

objConn.Open()

Dim objCommand as new OLEDBCommand(strSQL,objConn)
dlMusic.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
dlMusic.DataBind()

dlMusic.RepeatColumns = 1

This is the binding for datalist - dlMusic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top