Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 27th, 2006, 06:48 PM
Registered User
Join Date: Aug 2006
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....

Old August 31st, 2006, 11:40 PM
Friend of Wrox
Join Date: Feb 2006
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

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

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