:
: Can someone tell me why I cannot get the data from the Northwind database in MSQL Server 2000. I am trying to place the data in the data gride and disply it.
:
: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebWelcome.WebForm1"%>
: <%@ Import Namespace="System.Data"%>
: <%@ Import Namespace="System.Data.SqlClient"%>
:
: <HTML>
: <script language="VB" runat="server">
:
: Sub Page_Load(Scr As Object, E AS EventArgs)
: Dim myDataGrid as new DataGrid()
: Dim myConn As SqlConnection = New _
: SqlConnection("server=localhost;uid=sa;pwd=156977;database=Northwind")
:
: Dim myCommand As SQLCommand = New SQLCommand("select * form Customers", MyConn)
:
: myConn.Open()
:
: Dim DS AS SQLDataReader=myCommand.ExecuteReader()
:
: myDataGrid.DataSource= DS
: myDataGrid.DataBind()
:
: myConn.Close()
: End Sub
: </script>
:
: <body >
:
: <h3><font face="Verdana">Northwind Customers</font></h3>
: <asp:DataGrid ID="myDataGrid"
: width="70"
: BackColor="#FFFFFF"
: BorderColor="black"
: SHowFooter="False"
: CellPadding=3
: CellSpacing="0"
: Font-Name="Verdana"
: Font-Size="8pt"
: HeaderStyle-BackColor="#cfcfcf"
: EnableViewState="False"
: </asp:DataGrid>
:
: </body>
: </HTML>
:
:
Try removing this line from your code ...
Dim myDataGrid as new DataGrid()
Basically the .NET framework reads the <asp: tags, parses it out and creates an instance of the control for you. So "myDataGrid" will be a legitimate reference to a datagrid object as soon as the page load event occurs. Creating a new reference as shown above is effectively overwriting the reference that the .NET framework worked so hard to create and that is why it appears that your data-binding is not working.