Solved

Connection to MS SQL on page load

Posted on 2011-02-18
5
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net figure out error 3 47
Validation for a field in asp.net 3 31
CSS question 16 63
Manage big list of parameter list 8 27
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

710 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