Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Database stuff...
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Database stuff...

 Post Reply Post Reply Page  12>
Author
VBScript View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2004
Location: United Kingdom
Status: Offline
Points: 219
Post Options Post Options   Thanks (0) Thanks(0)   Quote VBScript Quote  Post ReplyReply Direct Link To This Post Topic: Database stuff...
    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.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
VBScript View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2004
Location: United Kingdom
Status: Offline
Points: 219
Post Options Post Options   Thanks (0) Thanks(0)   Quote VBScript Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Freon22 View Drop Down
Groupie
Groupie


Joined: 04 December 2005
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote Freon22 Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
VBScript View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2004
Location: United Kingdom
Status: Offline
Points: 219
Post Options Post Options   Thanks (0) Thanks(0)   Quote VBScript Quote  Post ReplyReply Direct Link To This Post Posted: 31 August 2006 at 8:08am
Thats great!

Do you know how to put the records into an array like:
rsCommon.GetRows()
Back to Top
MadDog View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 01 January 2002
Status: Offline
Points: 3008
Post Options Post Options   Thanks (0) Thanks(0)   Quote MadDog Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Freon22 View Drop Down
Groupie
Groupie


Joined: 04 December 2005
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote Freon22 Quote  Post ReplyReply Direct Link To This Post 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!
 
 
If you find any good infor out there please share.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.