Solved

Connection to MS SQL on page load

Posted on 2011-02-18
5
383 Views
Last Modified: 2012-05-11
Hi

I'm a newbie to asp.net moving from classic asp.

I've got my head around controls but need a bit more flexibility. I would really like to be able to connect to the database and query the database without using a control - can any point me in the right direction as I appear tom have met a large brick wall!

I'm using VWD 2010 Express & MS SQL

Many thanks in advance

Grant
0
Comment
Question by:Buzby58
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34925513
You can find a sample of talking to a database here (it's in C# but I can post a VB equivalent if needed):

     http://www.myvirtualplayground.co.uk/blog/fundamentals_reading_from_a_database_part_1
0
 

Author Comment

by:Buzby58
ID: 34925579
Hi Carl

Looks like just the sort of simple explanation I need - I'm working in VB so if it isn't too much hassle could I trouble you for that version!

Cheers

Grant
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34925647
Direct translation would be:
Dim connString As String = "Server=(local);Initial Catalog=AdventureWorks;Integrated Security=SSPI"
Dim conn As New SqlConnection(connString)

Dim cmd As New SqlCommand("SELECT [FirstName], [LastName] FROM [Person].[Contact]", conn)

conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()

While reader.Read()
      '// Method for reading fields same as for C# version
End While

conn.Close()

Open in new window

0
 

Author Comment

by:Buzby58
ID: 34926688
Easy when you know how . . . .

After much head scratching I've got it working in my aspx.vb file and loading with the required page.

Thank you for you help and the excellent primer article which I've also bookmarked - both much appreciated!

Cheers

Grant
0
 

Author Closing Comment

by:Buzby58
ID: 34926703
Really helpful and gave me a good steer to sorting out by problem! A big thanks
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now