Newbie Question

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>
<ASP:DataGrid 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>
</ASP:DataGrid>
</body>
</HTML>
 
A

Aytaç ÖZAY

Hi,

Are you sure that your DataSet has records? Verify it first. And also verify
that your method is calling when the page is loading.

Aytaç ÖZAY
 
G

Guest

What would be the easiest way to do this? I know there is records in the
database, but how could I verify that there are records in the dataset?

How can I verify that the method is calling on page_load?
 
A

Aytaç ÖZAY

Hi again,

You must run the programme in debug mode and you set the breakpoint after
that line MyCommand.Fill(ds,"Books") and you watch the
ds.Tables[0].Rows.Count property, if your brekpoint has never stop the
programme that means that your page load event hasn't been run at all. If it
was stopped the programme you can verify that your DataSet has any rows.

Have a nice work,

Aytaç ÖZAY
Software Developer
 
A

Aytaç ÖZAY

Hi again,

You must run the programme in debug mode and you set the breakpoint after
that line MyCommand.Fill(ds,"Books") and you watch the
ds.Tables[0].Rows.Count property, if your brekpoint has never stop the
programme that means that your page load event hasn't been run at all. If it
was stopped the programme you can verify that your DataSet has any rows.

Have a nice work,

Aytaç ÖZAY
Software Developer
 
A

Aytaç ÖZAY

Hi again,

You must run the programme in debug mode and you set the breakpoint after
that line MyCommand.Fill(ds,"Books") and you watch the
ds.Tables[0].Rows.Count property, if your brekpoint has never stop the
programme that means that your page load event hasn't been run at all. If it
was stopped the programme you can verify that your DataSet has any rows.

Have a nice work,

Aytaç ÖZAY
Software Developer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top