Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i load a datareader using web.confi file

Status
Not open for further replies.

viperbyte

Programmer
Apr 21, 2010
1
US
Hi everybody. How do I load a datareader in my default.aspx page while using a database connection defined in the web.config file. Please.
 
What exactly are you trying to do? Your question is very broad.
What have you tried so far?
 
how to access a database is indifferent whether the environment is a website, desktop, windows service, messaging bus, console, etc. data access is only concerned with accessing the database. what you do with the data after you have accessed the database is up to you.

to access the database you will be using ado.net.

being a web environment there are common approaches to incorporating ado.net into a website. Have a look at my FAQ on database connection management (see link in my signature). if you have any questions just ask.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
ViperByte

I use a connection I establish in my webconfig appsettings (or you can use the connectionstrings area) like this:


<appSettings>
<add key="MYconn" value="Data Source=MyServerIPadd;Initial Catalog=MYDbname;user=MYuser;Password=MYpwd;"/>
</appSettings>

Then I can establsih the connection in the code behind using:

Dim sqlconn As New SqlClient.SqlConnection(System.Configuration.ConfigurationManager.AppSettings("MYconn"))

One of the most most basic of ways to populate your reader:

Code:
Dim sqlconn As New SqlClient.SqlConnection(System.Configuration.ConfigurationManager.AppSettings("MYconn"))


Dim dr1 As SqlDataReader
Dim dr1cmd As New SqlCommand("You Sql here", sqlconn)


 sqlconn.Open()


Try

  dr1 = dr1cmd.ExecuteReader

Catch ex As System.Exception

End Try


While DR1.read
'do somthing
end while


sqlconn.Close()
sqlconn.Dispose()



The guys above are correct and they are experts. They have pulled my butt out of the fire several times. There are a variety of ways to accomplish what you trying to do but hopefully this will get you going in the right direction

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top