G
Guest
I'm performing the ASP Quickstart lessons, where I'm trying to get a datagrid
to fill with data from a SQL Server database. The code below runs, but the
datagrid doesn't display on the webpage. What am I doing wrong? I can add the
controls and add Conn, DA, DS, command objects from the toolbox, but I cannot
get it to run this way.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="WebApplication1.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<script Language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
'MyConnection = New SqlConnection("removed for security reasons")
MyCommand = New SqlDataAdapter("select * from Books", myConnection)
DS = new DataSet()
MyCommand.Fill(ds,"Books")
MyDataGrid.DataSource=ds.Tables("Books").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
</form>
<ASPataGrid id="MyDataGrid" runat="server" Width="700px"
BackColor="#CCCCFF" BorderColor="Black"
CellPadding="3" Font-Name="Verdana" Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd" EnableViewState="False"
Font-Names="Verdana">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</ASPataGrid>
</body>
</HTML>
to fill with data from a SQL Server database. The code below runs, but the
datagrid doesn't display on the webpage. What am I doing wrong? I can add the
controls and add Conn, DA, DS, command objects from the toolbox, but I cannot
get it to run this way.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="WebApplication1.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<script Language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
'MyConnection = New SqlConnection("removed for security reasons")
MyCommand = New SqlDataAdapter("select * from Books", myConnection)
DS = new DataSet()
MyCommand.Fill(ds,"Books")
MyDataGrid.DataSource=ds.Tables("Books").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
</form>
<ASPataGrid id="MyDataGrid" runat="server" Width="700px"
BackColor="#CCCCFF" BorderColor="Black"
CellPadding="3" Font-Name="Verdana" Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd" EnableViewState="False"
Font-Names="Verdana">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</ASPataGrid>
</body>
</HTML>