.NETGURU
Reuse a connection?
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-sqlclient' list.


Damian Barrow
-- Moved from [aspngfreeforall] to [ngfx-sqlclient] by Tim Musschoot <Click here to reveal e-mail address> --

I have two drop down lists, both of which reflect the returns of the
same stored procedure. How do I set the droip downs to use the same
data?

My code

<%@ Page Language=3D"VB" Debug=3D"true" %>
<%@ import Namespace=3D"System.Data" %>
<%@ import Namespace=3D"System.Data.SqlClient" %>
<%@ outputcache duration=3D"12000" varybyparam=3D"none" %>

<script runat=3D"server">

Sub Page_Load(Sender As Object, E As EventArgs)
=20
Dim ConnectionString As String =3D "Data Source=3Dxxx; Initial
Catalog=3Dxxx; User ID=3Dxxx; password=3Dxxx"
Dim CommandText As String =3D "PollData_getDates"
Dim myConnection As New SqlConnection(ConnectionString)
Dim myCommand As New SqlCommand(CommandText, myConnection)
=20
myCommand.CommandType =3D CommandType.StoredProcedure
myConnection.Open()
=20
date_list1.DataSource =3D
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
date_list1.DataBind()
'todo - ask the lists how to make this bit work :D

date_list2.DataSource =3D
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
date_list2.DataBind()
=20
End Sub

</script>
<html>
<head>
</head>
<body style=3D"FONT-FAMILY: arial">
<h2>Simple Stored Procedure=20
</h2>
<hr size=3D"1" />
<form runat=3D"server">
<asp:DropDownList id=3D"date_list1" runat=3D"server"
DataTextField=3D"nice_day" DataValueField=3D"dd_val"></asp:DropDownList>
<br>
<asp:DropDownList id=3D"date_list2" runat=3D"server"
DataTextField=3D"nice_day" DataValueField=3D"dd_val"></asp:DropDownList>
</form>
</body>
</html>

Reply to this message...
 
    
Jamie Dearnley
Hi Damian,
     Why don't you use a dataset instead of a datareader?

    Jamie

[Original message clipped]

Reply to this message...
 
    
James Avery
What Error are you getting? If you are going to use it twice you might
want to use a dataset, so you only hit the database once.

Dim oAdapter as New SqlDataAdapter(myCommand)
Dim dsData as New DataSet()
oAdapter.Fill(dsData)

Then just bind to dsData as many times as you want.

-----Original Message-----
From: Damian Barrow [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 23, 2002 8:04 AM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Reuse a connection?

-- Moved from [aspngfreeforall] to [ngfx-sqlclient] by Tim Musschoot
<Click here to reveal e-mail address> --

I have two drop down lists, both of which reflect the returns of the
same stored procedure. How do I set the droip downs to use the same
data?

My code

<%@ Page Language=3D"VB" Debug=3D"true" %>
<%@ import Namespace=3D"System.Data" %>
<%@ import Namespace=3D"System.Data.SqlClient" %>
<%@ outputcache duration=3D"12000" varybyparam=3D"none" %>

<script runat=3D"server">

Sub Page_Load(Sender As Object, E As EventArgs)
=20
Dim ConnectionString As String =3D "Data Source=3Dxxx; Initial
Catalog=3Dxxx; User ID=3Dxxx; password=3Dxxx"
Dim CommandText As String =3D "PollData_getDates"
Dim myConnection As New SqlConnection(ConnectionString)
Dim myCommand As New SqlCommand(CommandText, myConnection)
=20
myCommand.CommandType =3D CommandType.StoredProcedure
myConnection.Open()
=20
date_list1.DataSource =3D
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
date_list1.DataBind()
'todo - ask the lists how to make this bit work :D

date_list2.DataSource =3D
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
date_list2.DataBind()
=20
End Sub

</script>
<html>
<head>
</head>
<body style=3D"FONT-FAMILY: arial">
<h2>Simple Stored Procedure=20
</h2>
<hr size=3D"1" />
<form runat=3D"server">
<asp:DropDownList id=3D"date_list1" runat=3D"server"
DataTextField=3D"nice_day" DataValueField=3D"dd_val"></asp:DropDownList>
<br>
<asp:DropDownList id=3D"date_list2" runat=3D"server"
DataTextField=3D"nice_day" DataValueField=3D"dd_val"></asp:DropDownList>
</form>
</body>
</html>
| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Damian Barrow
>>> Why don't you use a dataset instead of a datareader?

Blank spot. And I have no idea what I'm doing :P
Thanks all.
Now - I know I should work this out myself but how do I rip out the
first 5 rows from dsData?

Cheers
Damian

-----Original Message-----
From: Jamie Dearnley [mailto:Click here to reveal e-mail address]=20
Sent: 23 July 2002 15:59
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: Reuse a connection?

Hi Damian,
     Why don't you use a dataset instead of a datareader?

    Jamie

[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address =3D YOUR =
ID=20
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp =3D JOIN/QUIT

_____________________________________________________________________
Travel Counsellors has scanned this message for all known viruses.

Reply to this message...
 
    
Jon Ceanfaglione
This should get you started

DataSet _ds;

foreach(DataTable _dt in _ds.Tables) //loop through tables
{
    foreach(DataRow _dr in _dt.Rows) //loop through rows
    {
        for(int i=0;i<_dr.ItemArray.Length;i++)//loop columns
        {
        Response.Write(_dr.ItemArray[i].ToString());
        }
    }
}

----Original Message-----
From: Damian Barrow [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 23, 2002 11:37 AM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: Reuse a connection?

>>> Why don't you use a dataset instead of a datareader?

Blank spot. And I have no idea what I'm doing :P
Thanks all.
Now - I know I should work this out myself but how do I rip out the
first 5 rows from dsData?

Cheers
Damian

-----Original Message-----
From: Jamie Dearnley [mailto:Click here to reveal e-mail address]
Sent: 23 July 2002 15:59
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: Reuse a connection?

Hi Damian,
     Why don't you use a dataset instead of a datareader?

    Jamie

[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

_____________________________________________________________________
Travel Counsellors has scanned this message for all known viruses.

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

__________________________________________________

The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.

Reply to this message...
 
    
James Avery
You can still bind to the dataset just like you were binding to the
reader. See my earlier post for the code.

-----Original Message-----
From: Damian Barrow [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 23, 2002 11:37 AM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: Reuse a connection?

>>> Why don't you use a dataset instead of a datareader?

Blank spot. And I have no idea what I'm doing :P
Thanks all.
Now - I know I should work this out myself but how do I rip out the
first 5 rows from dsData?

Cheers
Damian

-----Original Message-----
From: Jamie Dearnley [mailto:Click here to reveal e-mail address]
Sent: 23 July 2002 15:59
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: Reuse a connection?

Hi Damian,
     Why don't you use a dataset instead of a datareader?

    Jamie

[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

_____________________________________________________________________
Travel Counsellors has scanned this message for all known viruses.

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
 
System.Data.CommandBehavior
System.Data.CommandType
System.Data.DataRow
System.Data.DataSet
System.Data.DataTable
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.EventArgs
System.Web.UI.WebControls.DropDownList




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification