Solved

Connection to MS SQL on page load

Posted on 2011-02-18
5
384 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

23 Experts available now in Live!

Get 1:1 Help Now