Print Page | Close Window

Database stuff...

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=21165
Printed Date: 28 March 2026 at 12:37pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Database stuff...
Posted By: VBScript
Subject: Database stuff...
Date Posted: 29 August 2006 at 11:09am
I'm trying to learn ASP .Net (VB) and I can't figure out how to connect to a database using a method similar to using the ADODB.Connection and Recordset objects that you use in ASP.

Can someone give me an example of how to connect to a database using a method that allows MS SQL, mySQl and Access?

Thanks in advance.


-------------
http://www.james-r.co.uk" rel="no follow - James
http://www.gotrillian.com/?4498-20" rel="no follow - Trillian - M



Replies:
Posted By: michael
Date Posted: 29 August 2006 at 3:08pm
Well you can still use ADODB but why would you?
ASP.nets' beauty is that you can create Data Providers, so you create one for SQL Server maybe even one for ADODB but if you can create specialized ones. There is a mySQL .net Provider you can use as opposed to adodb.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: VBScript
Date Posted: 29 August 2006 at 3:15pm
Umm... ok....

Could you show me an example of how I can do this. I just want something that behavies like ADODB in the fact that I can place all the tables data into an array (arrData = rsCommon.GetRows()) etc...

All the examples I have found have used things like datagrids which i dont want to use.


-------------
http://www.james-r.co.uk" rel="no follow - James
http://www.gotrillian.com/?4498-20" rel="no follow - Trillian - M


Posted By: Freon22
Date Posted: 31 August 2006 at 5:21am

It is a little bit of a pain moving from vbscript to vb.net. But so far the closest thing I can find to our old way of doing thing is using the reader.

 
Here is an example of how I fill a dropdownlist using the reader.
 

Private Sub FillNameList()
 
NameList.Items.Clear()
 
'Define the Select statement.
Dim selectSql As String = "SELECT name, name_ID FROM tbNames"
 
'Define the ADO.NET objects.
 
Dim con As New SqlConnection(connectionString)

Dim cmd As New SqlCommand(selectSql, con)

Dim reader As SqlDataReader

'Try to open database and read information.

Try

con.Open()

reader = cmd.ExecuteReader()

'For each item, add the name to the displayed list box text,

'and store the name ID in the Value property.

Do While reader.Read()

Dim newItem As New ListItem()

newItem.Text = reader("name")

newItem.Value = reader("name_ID").ToString()

NameList.Items.Add(newItem)

Loop

'I want the default value in my dropdownlist be.
NameList.Items.Insert(0, New ListItem("---Choose One---", ""))

reader.Close()

Catch err As Exception

lblResults.Text = "Error in reading list of names. "

lblResults.Text &= err.Message

Finally

con.Close()

End Try

End Sub

The reader works a little like our old recordset, not the same but? Hope this helps some, you may want to get a good book on asp.net.


Posted By: VBScript
Date Posted: 31 August 2006 at 8:08am
Thats great!

Do you know how to put the records into an array like:
rsCommon.GetRows()


-------------
http://www.james-r.co.uk" rel="no follow - James
http://www.gotrillian.com/?4498-20" rel="no follow - Trillian - M


Posted By: MadDog
Date Posted: 31 August 2006 at 8:16am
ASP.Net doesnt support getRows.

I researched this months ago when trying to do something with ASP.Net


-------------
http://www.iportalx.net" rel="nofollow">


Posted By: Freon22
Date Posted: 31 August 2006 at 3:22pm
Here is a tutorial on arraylist, you can use the datareader to fill the arraylist. The problem that I have is alot of the example that I find on the net is using C#. I guess there are more C programmer out there then VB programmer. lol Anyway I have had to take an example that was written in C# try to understand it, then rewrite it in VB. What a pain!
 
http://aspnet101.com/aspnet101/tutorials.aspx?id=24 - http://aspnet101.com/aspnet101/tutorials.aspx?id=24
 
If you find any good infor out there please share.


Posted By: michael
Date Posted: 31 August 2006 at 5:46pm
If you have trouble translating code from c# use a website like this: http://www.carlosag.net/Tools/CodeTranslator/Default.aspx to do it for you. works well enough to get most things done.

As far as getrows goes. Once you populate the reader you have already a collection, why put it in another one and not just use the reader. You need to get off the asp mindset to do efficient asp.net coding otherwise you are just renaming files not doing much towards oop

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Freon22
Date Posted: 31 August 2006 at 6:26pm
That is cool  I'll save that link.
 



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net