Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Differences in Visual Studio Code


Message #1 by "Hugh McLaughlin" <hugh@k...> on Sun, 18 Aug 2002 02:25:59
Hello everyone and thanks for your help in advance.  I am learning to 
utilize Visual Studio .Net and am running into a problem with some basic 
code.  When I use the following in a simple ASPX page not compiled by 
Visual Studio:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>


<%
      		Dim myConnection As SQLConnection
      		Dim myCommand As SQLCommand
      		Dim myReader  As SQLDataReader
      		Dim SQL       As String      		Dim ConnStr   As 
String = "server=(local);uid=sa;pwd=;database=Northwind"

      		SQl = "select * from Employees"

      		myConnection = New SQLConnection(ConnStr)
      		myConnection.Open()

      		myCommand = New SQLCommand(SQL, myConnection)

      		myReader = myCommand.ExecuteReader()

		myDatagrid.DataSource=myReader

		Page.Databind()

		
%>

 <ASP:DataGrid id="MyDataGrid" runat="server" />

 It works fine.  However, when I move the script code to a code-behind 
and make the changes for the imports, I get a compiler error the tells me 
that "Datasource" is not a member of the web application.  What am I 
doing wrong and why doesn't it work?  Any help would be greatly 
appreciated.  Thanks.
Message #2 by Imar Spaanjaars <Imar@S...> on Sun, 18 Aug 2002 08:36:28 +0200
Hi Hugh,

Did you add a declaration for the datagrid control in the code behind file? 
To be able to use the grid in the code behind, you'll need something like this:

         Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid

Visual Studio will add this declaration when you switch from HTML view to 
Design view. But if you haven't switched yet, you'll need to add it manually.

HtH

Imar



At 02:25 AM 8/18/2002 +0000, you wrote:
>Hello everyone and thanks for your help in advance.  I am learning to
>utilize Visual Studio .Net and am running into a problem with some basic
>code.  When I use the following in a simple ASPX page not compiled by
>Visual Studio:
>
><%@ Import Namespace="System.Data" %>
><%@ Import Namespace="System.Data.SqlClient" %>
>
>
><%
>                 Dim myConnection As SQLConnection
>                 Dim myCommand As SQLCommand
>                 Dim myReader  As SQLDataReader
>                 Dim SQL       As String                 Dim ConnStr   As
>String = "server=(local);uid=sa;pwd=;database=Northwind"
>
>                 SQl = "select * from Employees"
>
>                 myConnection = New SQLConnection(ConnStr)
>                 myConnection.Open()
>
>                 myCommand = New SQLCommand(SQL, myConnection)
>
>                 myReader = myCommand.ExecuteReader()
>
>                 myDatagrid.DataSource=myReader
>
>                 Page.Databind()
>
>
>%>
>
>  <ASP:DataGrid id="MyDataGrid" runat="server" />
>
>  It works fine.  However, when I move the script code to a code-behind
>and make the changes for the imports, I get a compiler error the tells me
>that "Datasource" is not a member of the web application.  What am I
>doing wrong and why doesn't it work?  Any help would be greatly
>appreciated.  Thanks.
>---
>Beginning ASP.NET 1.0 with C#
>Entirely revised and updated for the final release,
>provides a step-by-step introduction with plenty of
>worked examples to help you to gain a deep understanding
>of what ASP.NET is all about, and how you can harness it
>to build powerful web applications.
>http://www.wrox.com/acon11.asp?ISBN=1861007345


Message #3 by "Hugh McLaughlin" <hugh@k...> on Mon, 19 Aug 2002 12:54:13
Hi Imar.

I am actaully paating the code into Visual Studio, so it is already 
inserting the line of code:


Imports System.Data
Imports System.Data.SqlClient

Public Class MyDatagrid
    Inherits System.Web.UI.Page


Does a datasource need to be created visually before it will compile 
properly in Visual Studio?  I simply cut and pasted, then compiled.



Hello everyone and thanks for your help in advance.  I am learning to 
utilize Visual Studio .Net and am running into a problem with some basic 
code.  When I use the following in a simple ASPX page not compiled by 
Visual Studio:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>


<%
      		Dim myConnection As SQLConnection
      		Dim myCommand As SQLCommand
      		Dim myReader  As SQLDataReader
      		Dim SQL       As String      		Dim ConnStr   As 
String = "server=(local);uid=sa;pwd=;database=Northwind"

      		SQl = "select * from Employees"

      		myConnection = New SQLConnection(ConnStr)
      		myConnection.Open()

      		myCommand = New SQLCommand(SQL, myConnection)

      		myReader = myCommand.ExecuteReader()

		myDatagrid.DataSource=myReader

		Page.Databind()

		
%>

 <ASP:DataGrid id="MyDataGrid" runat="server" />

 It works fine.  However, when I move the script code to a code-behind 
and make the changes for the imports, I get a compiler error the tells me 
that "Datasource" is not a member of the web application.  What am I 
doing wrong and why doesn't it work?  Any help would be greatly 
appreciated.  Thanks.aa

> Hi Hugh,

Did you add a declaration for the datagrid control in the code behind 
file? 
To be able to use the grid in the code behind, you'll need something like 
this:

         Protected WithEvents MyDataGrid As 
System.Web.UI.WebControls.DataGrid

Visual Studio will add this declaration when you switch from HTML view to 
Design view. But if you haven't switched yet, you'll need to add it 
manually.

HtH

Imar



At 02:25 AM 8/18/2002 +0000, you wrote:
>Hello everyone and thanks for your help in advance.  I am learning to
>utilize Visual Studio .Net and am running into a problem with some basic
>code.  When I use the following in a simple ASPX page not compiled by
>Visual Studio:
>
><%@ Import Namespace="System.Data" %>
><%@ Import Namespace="System.Data.SqlClient" %>
>
>
><%
>                 Dim myConnection As SQLConnection
>                 Dim myCommand As SQLCommand
>                 Dim myReader  As SQLDataReader
>                 Dim SQL       As String                 Dim ConnStr   As
>String = "server=(local);uid=sa;pwd=;database=Northwind"
>
>                 SQl = "select * from Employees"
>
>                 myConnection = New SQLConnection(ConnStr)
>                 myConnection.Open()
>
>                 myCommand = New SQLCommand(SQL, myConnection)
>
>                 myReader = myCommand.ExecuteReader()
>
>                 myDatagrid.DataSource=myReader
>
>                 Page.Databind()
>
>
>%>
>
>  <ASP:DataGrid id="MyDataGrid" runat="server" />
>
>  It works fine.  However, when I move the script code to a code-behind
>and make the changes for the imports, I get a compiler error the tells me
>that "Datasource" is not a member of the web application.  What am I
>doing wrong and why doesn't it work?  Any help would be greatly
>appreciated.  Thanks.
>---
>Beginning ASP.NET 1.0 with C#
>Entirely revised and updated for the final release,
>provides a step-by-step introduction with plenty of
>worked examples to help you to gain a deep understanding
>of what ASP.NET is all about, and how you can harness it
>to build powerful web applications.
>http://www.wrox.com/acon11.asp?ISBN=1861007345


Message #4 by Imar Spaanjaars <Imar@S...> on Mon, 19 Aug 2002 17:47:51 +0200
Hi Hugh,

AFAICS from your code, MyDatagrid is your page / main class and not the 
variable for the Datagrid ON the page.
(How about you post both the (trimmed down) ASPX and VB code so we can take 
a look.)

Anyway, in short it should look like this:

ASPX page, called MyASPPageWithADataGrid.aspx
<ASP:DataGrid id="MyDataGrid" runat="server" />

Code Behind page:
Imports System.Data
Imports System.Data.SqlClient

Public Class MyASPPageWithADataGrid
     Inherits System.Web.UI.Page

         Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid
         ' Class implementation here
End Class

So, your class name is named after the ASPX page (this is by default in 
VS.NET) so the class is called MyASPPageWithADataGrid in my example.
Then ON that page you have a datagrid called MyDataGrid with a declaration 
in the code behind with the same name to enable you to access the control 
programmatically.

HtH

Imar



At 12:54 PM 8/19/2002 +0000, you wrote:
>Hi Imar.
>
>I am actaully paating the code into Visual Studio, so it is already
>inserting the line of code:
>
>
>Imports System.Data
>Imports System.Data.SqlClient
>
>Public Class MyDatagrid
>     Inherits System.Web.UI.Page
>
>
>Does a datasource need to be created visually before it will compile
>properly in Visual Studio?  I simply cut and pasted, then compiled.
>
>
>
>Hello everyone and thanks for your help in advance.  I am learning to
>utilize Visual Studio .Net and am running into a problem with some basic
>code.  When I use the following in a simple ASPX page not compiled by
>Visual Studio:
>
><%@ Import Namespace="System.Data" %>
><%@ Import Namespace="System.Data.SqlClient" %>
>
>
><%
>                 Dim myConnection As SQLConnection
>                 Dim myCommand As SQLCommand
>                 Dim myReader  As SQLDataReader
>                 Dim SQL       As String                 Dim ConnStr   As
>String = "server=(local);uid=sa;pwd=;database=Northwind"
>
>                 SQl = "select * from Employees"
>
>                 myConnection = New SQLConnection(ConnStr)
>                 myConnection.Open()
>
>                 myCommand = New SQLCommand(SQL, myConnection)
>
>                 myReader = myCommand.ExecuteReader()
>
>                 myDatagrid.DataSource=myReader
>
>                 Page.Databind()
>
>
>%>
>
>  <ASP:DataGrid id="MyDataGrid" runat="server" />
>
>  It works fine.  However, when I move the script code to a code-behind
>and make the changes for the imports, I get a compiler error the tells me
>that "Datasource" is not a member of the web application.  What am I
>doing wrong and why doesn't it work?  Any help would be greatly
>appreciated.  Thanks.aa
>
> > Hi Hugh,
>
>Did you add a declaration for the datagrid control in the code behind
>file?
>To be able to use the grid in the code behind, you'll need something like
>this:
>
>          Protected WithEvents MyDataGrid As
>System.Web.UI.WebControls.DataGrid
>
>Visual Studio will add this declaration when you switch from HTML view to
>Design view. But if you haven't switched yet, you'll need to add it
>manually.
>
>HtH
>
>Imar
>
>
>
>At 02:25 AM 8/18/2002 +0000, you wrote:
> >Hello everyone and thanks for your help in advance.  I am learning to
> >utilize Visual Studio .Net and am running into a problem with some basic
> >code.  When I use the following in a simple ASPX page not compiled by
> >Visual Studio:
> >
> ><%@ Import Namespace="System.Data" %>
> ><%@ Import Namespace="System.Data.SqlClient" %>
> >
> >
> ><%
> >                 Dim myConnection As SQLConnection
> >                 Dim myCommand As SQLCommand
> >                 Dim myReader  As SQLDataReader
> >                 Dim SQL       As String                 Dim ConnStr   As
> >String = "server=(local);uid=sa;pwd=;database=Northwind"
> >
> >                 SQl = "select * from Employees"
> >
> >                 myConnection = New SQLConnection(ConnStr)
> >                 myConnection.Open()
> >
> >                 myCommand = New SQLCommand(SQL, myConnection)
> >
> >                 myReader = myCommand.ExecuteReader()
> >
> >                 myDatagrid.DataSource=myReader
> >
> >                 Page.Databind()
> >
> >
> >%>
> >
> >  <ASP:DataGrid id="MyDataGrid" runat="server" />
> >
> >  It works fine.  However, when I move the script code to a code-behind
> >and make the changes for the imports, I get a compiler error the tells me
> >that "Datasource" is not a member of the web application.  What am I
> >doing wrong and why doesn't it work?  Any help would be greatly
> >appreciated.  Thanks.
> >---
> >Beginning ASP.NET 1.0 with C#
> >Entirely revised and updated for the final release,
> >provides a step-by-step introduction with plenty of
> >worked examples to help you to gain a deep understanding
> >of what ASP.NET is all about, and how you can harness it
> >to build powerful web applications.
> >http://www.wrox.com/acon11.asp?ISBN=1861007345
>
>
>---
>Beginning ASP.NET 1.0 with C#
>Entirely revised and updated for the final release,
>provides a step-by-step introduction with plenty of
>worked examples to help you to gain a deep understanding
>of what ASP.NET is all about, and how you can harness it
>to build powerful web applications.
>http://www.wrox.com/acon11.asp?ISBN=1861007345


Message #5 by "Hugh McLaughlin" <hugh@k...> on Mon, 19 Aug 2002 23:33:39
Hi Imar.  Thanks for your help.  The code for the ASPPX page is:

<%@ Page Language="vb" AutoEventWireup="false" 
Codebehind="MyDatagrid.aspx.vb" Inherits="WebApplication1.MyDatagrid"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>MyDatagrid</title>
		<meta name="GENERATOR" content="Microsoft Visual 
Studio.NET 7.0">
		<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" 
content="http://schemas.microsoft.com/intellisense/ie5">
	</head>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<ASP:DataGrid id="MyDataGrid" runat="server" />
		</form>
	</body>
</html>

and the code for the code behind is:

Imports System.Data
Imports System.Data.SqlClient

Public Class MyDatagrid
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub 
InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
        Dim myConnection As SQLConnection
        Dim myCommand As SQLCommand
        Dim myReader As SQLDataReader
        Dim SQL As String

        Dim ConnStr As String = "server
(local);uid=sa;pwd=katie;database=Northwind"

        SQL = "select * from Employees"

        myConnection = New SQLConnection(ConnStr)
        myConnection.Open()

        myCommand = New SQLCommand(SQL, myConnection)

        myReader = myCommand.ExecuteReader()

        MyDatagrid.Datasource = myReader

        Page.DataBind()
    End Sub

End Class


The error is thrown on the MyDataGird.Datasource=myReader.  The error is
"Datasource" is not a member of WebApplication1.MyDatagrid.aspx.

Again, thanks for your help.

> Hi Hugh,

AFAICS from your code, MyDatagrid is your page / main class and not the 
variable for the Datagrid ON the page.
(How about you post both the (trimmed down) ASPX and VB code so we can 
take 
a look.)

Anyway, in short it should look like this:

ASPX page, called MyASPPageWithADataGrid.aspx
<ASP:DataGrid id="MyDataGrid" runat="server" />

Code Behind page:
Imports System.Data
Imports System.Data.SqlClient

Public Class MyASPPageWithADataGrid
     Inherits System.Web.UI.Page

         Protected WithEvents MyDataGrid As 
System.Web.UI.WebControls.DataGrid
         ' Class implementation here
End Class

So, your class name is named after the ASPX page (this is by default in 
VS.NET) so the class is called MyASPPageWithADataGrid in my example.
Then ON that page you have a datagrid called MyDataGrid with a 
declaration 
in the code behind with the same name to enable you to access the control 
programmatically.

HtH

Imar



At 12:54 PM 8/19/2002 +0000, you wrote:
>Hi Imar.
>
>I am actaully paating the code into Visual Studio, so it is already
>inserting the line of code:
>
>
>Imports System.Data
>Imports System.Data.SqlClient
>
>Public Class MyDatagrid
>     Inherits System.Web.UI.Page
>
>
>Does a datasource need to be created visually before it will compile
>properly in Visual Studio?  I simply cut and pasted, then compiled.
>
>
>
>Hello everyone and thanks for your help in advance.  I am learning to
>utilize Visual Studio .Net and am running into a problem with some basic
>code.  When I use the following in a simple ASPX page not compiled by
>Visual Studio:
>
><%@ Import Namespace="System.Data" %>
><%@ Import Namespace="System.Data.SqlClient" %>
>
>
><%
>                 Dim myConnection As SQLConnection
>                 Dim myCommand As SQLCommand
>                 Dim myReader  As SQLDataReader
>                 Dim SQL       As String                 Dim ConnStr   As
>String = "server=(local);uid=sa;pwd=;database=Northwind"
>
>                 SQl = "select * from Employees"
>
>                 myConnection = New SQLConnection(ConnStr)
>                 myConnection.Open()
>
>                 myCommand = New SQLCommand(SQL, myConnection)
>
>                 myReader = myCommand.ExecuteReader()
>
>                 myDatagrid.DataSource=myReader
>
>                 Page.Databind()
>
>
>%>
>
>  <ASP:DataGrid id="MyDataGrid" runat="server" />
>
>  It works fine.  However, when I move the script code to a code-behind
>and make the changes for the imports, I get a compiler error the tells me
>that "Datasource" is not a member of the web application.  What am I
>doing wrong and why doesn't it work?  Any help would be greatly
>appreciated.  Thanks.aa
>
> > Hi Hugh,
>
>Did you add a declaration for the datagrid control in the code behind
>file?
>To be able to use the grid in the code behind, you'll need something like
>this:
>
>          Protected WithEvents MyDataGrid As
>System.Web.UI.WebControls.DataGrid
>
>Visual Studio will add this declaration when you switch from HTML view to
>Design view. But if you haven't switched yet, you'll need to add it
>manually.
>
>HtH
>
>Imar
>
>
>
>At 02:25 AM 8/18/2002 +0000, you wrote:
> >Hello everyone and thanks for your help in advance.  I am learning to
> >utilize Visual Studio .Net and am running into a problem with some 
basic
> >code.  When I use the following in a simple ASPX page not compiled by
> >Visual Studio:
> >
> ><%@ Import Namespace="System.Data" %>
> ><%@ Import Namespace="System.Data.SqlClient" %>
> >
> >
> ><%
> >                 Dim myConnection As SQLConnection
> >                 Dim myCommand As SQLCommand
> >                 Dim myReader  As SQLDataReader
> >                 Dim SQL       As String                 Dim ConnStr   
As
> >String = "server=(local);uid=sa;pwd=;database=Northwind"
> >
> >                 SQl = "select * from Employees"
> >
> >                 myConnection = New SQLConnection(ConnStr)
> >                 myConnection.Open()
> >
> >                 myCommand = New SQLCommand(SQL, myConnection)
> >
> >                 myReader = myCommand.ExecuteReader()
> >
> >                 myDatagrid.DataSource=myReader
> >
> >                 Page.Databind()
> >
> >
> >%>
> >
> >  <ASP:DataGrid id="MyDataGrid" runat="server" />
> >
> >  It works fine.  However, when I move the script code to a code-behind
> >and make the changes for the imports, I get a compiler error the tells 
me
> >that "Datasource" is not a member of the web application.  What am I
> >doing wrong and why doesn't it work?  Any help would be greatly
> >appreciated.  Thanks.
> >---
> >Beginning ASP.NET 1.0 with C#
> >Entirely revised and updated for the final release,
> >provides a step-by-step introduction with plenty of
> >worked examples to help you to gain a deep understanding
> >of what ASP.NET is all about, and how you can harness it
> >to build powerful web applications.
> >http://www.wrox.com/acon11.asp?ISBN=1861007345
>
>
>---
>Beginning ASP.NET 1.0 with C#
>Entirely revised and updated for the final release,
>provides a step-by-step introduction with plenty of
>worked examples to help you to gain a deep understanding
>of what ASP.NET is all about, and how you can harness it
>to build powerful web applications.
>http://www.wrox.com/acon11.asp?ISBN=1861007345


Message #6 by Imar Spaanjaars <Imar@S...> on Tue, 20 Aug 2002 07:50:19 +0200
Hi Hugh,

Well, it looks like what I said in my previous e-mail: you're mixing up the 
class name and the control name.

You have a class called MyDataGrid which is the base class that the ASPX 
page inherits from. On that page you have a data control, called MyDataGrid.
Those names can't be the same. How would the compiler know whether you were 
referencing the page or the datagrid control.

So change the ASPX page to this:

<ASP:DataGrid id="MyDataGridControl" runat="server" />
(I added the word Control)

Then, in the code behind:

Public Class MyDataGrid
         Inherits System.Web.UI.Page
                 Protected WithEvents MyDataGridControl As 
System.Web.UI.WebControls.DataGrid
                 ' Class implementation here

                 Bla bla bla (Page load method here)
                         MyDataGridControl .Datasource = myReader
End Class

HtH

Imar


At 11:33 PM 8/19/2002 +0000, you wrote:
>Hi Imar.  Thanks for your help.  The code for the ASPPX page is:
>
><%@ Page Language="vb" AutoEventWireup="false"
>Codebehind="MyDatagrid.aspx.vb" Inherits="WebApplication1.MyDatagrid"%>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
>and the code for the code behind is:
>
>Imports System.Data
>Imports System.Data.SqlClient
>
>Public Class MyDatagrid
>     Inherits System.Web.UI.Page
>
>#Region " Web Form Designer Generated Code "
>
>     'This call is required by the Web Form Designer.
>     <System.Diagnostics.DebuggerStepThrough()> Private Sub
>InitializeComponent()
>
>     End Sub
>
>     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Init
>         'CODEGEN: This method call is required by the Web Form Designer
>         'Do not modify it using the code editor.
>         InitializeComponent()
>     End Sub
>
>#End Region
>
>     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
>         Dim myConnection As SQLConnection
>         Dim myCommand As SQLCommand
>         Dim myReader As SQLDataReader
>         Dim SQL As String
>
>         Dim ConnStr As String = "server
>(local);uid=sa;pwd=katie;database=Northwind"
>
>         SQL = "select * from Employees"
>
>         myConnection = New SQLConnection(ConnStr)
>         myConnection.Open()
>
>         myCommand = New SQLCommand(SQL, myConnection)
>
>         myReader = myCommand.ExecuteReader()
>
>         MyDatagrid.Datasource = myReader
>
>         Page.DataBind()
>     End Sub
>
>End Class
>
>
>The error is thrown on the MyDataGird.Datasource=myReader.  The error is
>"Datasource" is not a member of WebApplication1.MyDatagrid.aspx.
>
>Again, thanks for your help.


Message #7 by "Hugh McLaughlin" <hugh@k...> on Thu, 22 Aug 2002 21:55:10
Thanks Imar.  I had to look at this a few times to understand what you 
meant, but it makes perfect sense.  Thanks for the help.
> Hi Hugh,

Well, it looks like what I said in my previous e-mail: you're mixing up 
the 
class name and the control name.

You have a class called MyDataGrid which is the base class that the ASPX 
page inherits from. On that page you have a data control, called 
MyDataGrid.
Those names can't be the same. How would the compiler know whether you 
were 
referencing the page or the datagrid control.

So change the ASPX page to this:

<ASP:DataGrid id="MyDataGridControl" runat="server" />
(I added the word Control)

Then, in the code behind:

Public Class MyDataGrid
         Inherits System.Web.UI.Page
                 Protected WithEvents MyDataGridControl As 
System.Web.UI.WebControls.DataGrid
                 ' Class implementation here

                 Bla bla bla (Page load method here)
                         MyDataGridControl .Datasource = myReader
End Class

HtH

Imar


At 11:33 PM 8/19/2002 +0000, you wrote:
>Hi Imar.  Thanks for your help.  The code for the ASPPX page is:
>
><%@ Page Language="vb" AutoEventWireup="false"
>Codebehind="MyDatagrid.aspx.vb" Inherits="WebApplication1.MyDatagrid"%>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
>and the code for the code behind is:
>
>Imports System.Data
>Imports System.Data.SqlClient
>
>Public Class MyDatagrid
>     Inherits System.Web.UI.Page
>
>#Region " Web Form Designer Generated Code "
>
>     'This call is required by the Web Form Designer.
>     <System.Diagnostics.DebuggerStepThrough()> Private Sub
>InitializeComponent()
>
>     End Sub
>
>     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Init
>         'CODEGEN: This method call is required by the Web Form Designer
>         'Do not modify it using the code editor.
>         InitializeComponent()
>     End Sub
>
>#End Region
>
>     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
>         Dim myConnection As SQLConnection
>         Dim myCommand As SQLCommand
>         Dim myReader As SQLDataReader
>         Dim SQL As String
>
>         Dim ConnStr As String = "server
>(local);uid=sa;pwd=katie;database=Northwind"
>
>         SQL = "select * from Employees"
>
>         myConnection = New SQLConnection(ConnStr)
>         myConnection.Open()
>
>         myCommand = New SQLCommand(SQL, myConnection)
>
>         myReader = myCommand.ExecuteReader()
>
>         MyDatagrid.Datasource = myReader
>
>         Page.DataBind()
>     End Sub
>
>End Class
>
>
>The error is thrown on the MyDataGird.Datasource=myReader.  The error is
>"Datasource" is not a member of WebApplication1.MyDatagrid.aspx.
>
>Again, thanks for your help.


Message #8 by Imar Spaanjaars <Imar@S...> on Thu, 22 Aug 2002 22:54:47 +0200
You're welcome.

Imar


At 09:55 PM 8/22/2002 +0000, you wrote:
>Thanks Imar.  I had to look at this a few times to understand what you
>meant, but it makes perfect sense.  Thanks for the help.
> > Hi Hugh,
>



  Return to Index