Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 25th, 2005, 08:02 PM
Authorized User
 
Join Date: Nov 2004
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to don baroo Send a message via Yahoo to don baroo
Default Compilation Error

Hi,
I'm new to asp.net. I tried running the code below

<%@ Page Language="VB" %>

<% Import Namespace="System.Data" %>
<% Import Namespace="System.Data.sqlClient" %>

<script runat="server">
    sub Page_Load(Scr As Object, e As EventArgs)
        Dim myConnection As SqlConnection
        Dim myCommand As SqlDataAdapter


        myConnection = new_
    SqlConnection("server=localhost;uid=sa;pwd=;" _
                & "database=pubs")
            myCommand = new SqlDataAdapter("SELECT * FROM Authors", _
                myConnection)

            Dim ds As DataSet = new DataSet()
            myCommand.Fill(ds)

            MyDataGrid.DataSource = ds
            MyDataGrid.DataBind()

    End Sub
</script>

<html><body>
    <h3>
    </h3>
    <asp:DataGrid id="MyDataGrid" runat="server"
        Width="700"
        BackColor="#ccccff"
        BorderColor="black"
        ShowFooter="false"
        CellPadding=3
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="8pt"
        HeaderStyle-BackColor="#aaaadd"
        MaintainState="false"

    />
</body></html>

and this is the error I got:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'Import' is not declared.

Source Error:



Line 1: <%@ Page Language="VB" %>
Line 2:
Line 3: <% Import Namespace="System.Data" %>
Line 4: <% Import Namespace="System.Data.sqlClient" %>
Line 5:


Source File: c:\inetpub\wwwroot\aspnet\datagrid.aspx Line: 3

Can anyone help me out please. very urgent.

Thanks

 
Old August 25th, 2005, 10:57 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Your Import syntax is incorrect. In your code behind do this:
Imports System.Data
Imports System.Data.sqlClient

Do this above the page class declaration

 
Old August 26th, 2005, 08:05 PM
Authorized User
 
Join Date: Nov 2004
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to don baroo Send a message via Yahoo to don baroo
Default

Thanks jbenson001

I made a few changes. Here is the new code

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

    sub Page_Load(Scr As Object, e As EventArgs)
        Dim myConnection As SqlConnection
        Dim myCommand As SqlDataAdapter


        myConnection = new _
    SqlConnection("server=GH010033D;uid=sa;pwd=;" _
                & "database=pubs")
            myCommand = new SqlDataAdapter("SELECT * FROM Authors", _
                myConnection)

            Dim ds As DataSet = new DataSet()
            myCommand.Fill(ds)

            MyDataGrid.DataSource = ds
            MyDataGrid.DataBind()

    End Sub
</script>

<html><body>
    <h3>
    </h3>
    <asp:DataGrid id="MyDataGrid" runat="server"
        Width="700"
        BackColor="#ccccff"
        BorderColor="black"
        ShowFooter="false"
        CellPadding=3
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="8pt"
        HeaderStyle-BackColor="#aaaadd"
        MaintainState="false"

    />
</body></html>

and This is the error I get:

Server Error in '/' Application.
--------------------------------------------------------------------------------

SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.

Source Error:


Line 17:
Line 18: Dim ds As DataSet = new DataSet()
Line 19: myCommand.Fill(ds)
Line 20:
Line 21: MyDataGrid.DataSource = ds


Source File: c:\inetpub\wwwroot\aspnet\datagrid.aspx Line: 19

Stack Trace:


[SqlException: SQL Server does not exist or access denied.]
   System.Data.SqlClient.ConnectionPool.GetConnection (Boolean& isInTransaction) +473
   System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
   System.Data.SqlClient.SqlConnection.Open() +384
   System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection, ConnectionState& originalState) +44
   System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +38
   ASP.datagrid_aspx.Page_Load(Object Scr, EventArgs e) in c:\inetpub\wwwroot\aspnet\datagrid.aspx:19
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731

 I believe it has something to do with my SQL Server. I have been changing permissions but I still get the same error message. Can andyone help me?

Cheers.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation Error furqanms Pro Java 2 September 28th, 2007 11:22 AM
compilation error pratik28 C# 1 September 24th, 2006 07:39 AM
Compilation Error allyant ASP.NET 2.0 Basics 1 August 5th, 2006 05:51 PM
Compilation error Giri ASP.NET 1.0 and 1.1 Basics 3 August 3rd, 2005 04:14 PM
compilation error saint Classic ASP Databases 2 June 23rd, 2003 04:08 AM





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