Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Connection to MS SQL on page load

Posted on 2011-02-18
5
Medium Priority
?
392 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

877 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