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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DSN Database connection <asp:DataSource>

Status
Not open for further replies.

draigGoch

Programmer
Feb 10, 2005
166
GB
Hi there, hope you can help me, I am in the process of updating our company's web pages from asp to asp.net, and have run into a problem accessing database.

I am trying to make the most of asp.net's features including the <asp:repeater /> tag, but i need to have a data source tag. I managed to connect to the database normally like so:

Dim objConn = Server.CreateObject("ADODB.Connection")
Dim rstSource = Server.CreateObject("ADODB.Recordset")
Dim strSQL, myStr
objConn.Open ("DSN=myDSNConnection")
strSQL = "SELECT * FROM myTable ORDER BY fieldOne;"
rstSource= objConn.Execute(strSQL)

Do while not rstSource.eof
myStr &= rstSource("Cyfenw").Value & "<br/>"
rstSource.MoveNext
loop
myContent.text = myStr

but I don't know how to put this in a dtatSource tag - I've found loads of tutorials that show how to do it with normal connections to databases but not using the DSN.

Any help will be appreciated. Thanks

Gareth

A computer always does what you tell it to, but rarely does what you want it to.....
 
Firstly, you haven't declared any variable types and you are using a classic ASP method of accessing data (have a look at faq855-5662 on how you should be doing it). Secondly, rather than looping through the data, simply set the DataSource property to the DataTable that you create, and then call the Repeaters DataBind method.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Sorry, i am new to asp.net. I am updating the web pages at work, and all i know about the connection is the "DSN=myDSNConnection". I have no idea where database resides.

I don't know what to do with the information in the link you sent me (thanks anyway!)

This method isn't listed in the faq, but is this correct?

<asp:SqlDataSource id="BookSource" Runat="Server"
ProviderName="System.Data.OleDb"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=c:\eCommerce\Databases\BooksDB.mdb"
SelectCommand="SELECT BookID, BookType, BookTitle, BookPrice FROM Books
WHERE BookType = 'Database'
ORDER BY BookTitle"/>


And if so, what do i put in the connectionString field?

I am new to this database lark! I'm a designer by trade and need all of the help I can get!


A computer always does what you tell it to, but rarely does what you want it to.....
 
You can use the SqlDataSource instead of the code that the FAQ listed if you so wish. If you need to enter a connection string, check out faq855-5780.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I don't know the location of the data source - just the dsn. Is there anyway of connecting?

A computer always does what you tell it to, but rarely does what you want it to.....
 
Is there any way of connecting to a dsn with asp.net?

A computer always does what you tell it to, but rarely does what you want it to.....
 
Yes, just use any of the methods in the last FAQ I posted


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top