Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 27th, 2006, 06:48 PM
Registered User
Join Date: Aug 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default asp.net 2 accessing sql database code problem...

I'm having problems with the code to connect to an SQL DataBase...i'm not experienced with asp.net.

 I had once VB.NET 2003 and SQL Server 2000 installed. Recently i installed VB.NET 2005 and SQL Server 2005, becouse i couldn't install the earlier VB and SQL (problems with install) so i install the new versions of VB and SQL 2005, but this is like new to me.

 The problem is that there is new features that i'm not familiarized with...I have this code, a simple code to retrieve data to the webform:


 Imports System.Data.SqlClient

Partial Class data-ask
    Inherits System.Web.UI.Page

    Private Sub page_load()

        Dim connection As SqlConnection
        Dim mycommand As SqlCommand
        Dim myDataReader As SqlDataReader
        Dim SQLStmt As String

        connection = New SqlConnection("Server=matrix\WebSite1;uid=sa;pwd=1 234;database=aspnet-books;trusted_connection=yes")

        SQLStmt = "SELECT * FROM books "
        mycommand = New SqlCommand(SQLStmt, connection)
        myDataReader = mycommand.ExecuteReader()

        While myDataReader.Read()
            Response.Write(myDataReader.Item("books_name") & " - " & myDataReader.Item("book_price") & " Euros<br>")
        End While


    End Sub

End Class

What happens is that when i load, the page is blank (no errors is shown) just blank page.

I don't know if the connection to database(outside the code) is right (permitions, etc...)

Can anyone tell me what is the problem?

 Thank you....

Reply With Quote
  #2 (permalink)  
Old August 31st, 2006, 11:40 PM
Friend of Wrox
Join Date: Feb 2006
Location: , , USA.
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts

Your code is mostly correct. All you need to do now is properly override the page.Load event like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Currently your function never gets run when you load your page.

Neil Timmerman
Veris Consulting
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net & sql server database naeem.net ASP.NET 2.0 Professional 13 July 18th, 2007 02:10 PM
Problem accessing a .dll component in asp.net page ng4123 ASP.NET 1.0 and 1.1 Basics 5 May 10th, 2006 07:31 AM
asp.net code to insert image in to database madhusrp ASP.NET 1.0 and 1.1 Professional 2 March 16th, 2006 02:54 AM
Error while accessing SQL data from ASP.NET manisha2578 ASP.NET 1.0 and 1.1 Basics 2 February 26th, 2006 03:18 AM
store html code in a sql database through ASP.NET jmjyiannis VB.NET 2002/2003 Basics 0 July 9th, 2004 01:36 PM

All times are GMT -4. The time now is 08:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.