My datagrid does not show the query from dataset

G

Guest

Hi,

I am new in ASP.Net. I used 2 ways of coding to get the same result. The
first one is by typing all the codes directly to the asp.net page and it
works. The code looks like this:

<%@ import namespace = "System.Data" %>
<%@ import namespace = "System.Data.SQLClient" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="vb" runat="server">
Sub Page_Load()
Dim strConnection As String
Dim strSQL As String
Dim objDataSet As New DataSet()
Dim objConnection As SQLConnection
Dim objAdapter As SQLDataAdapter
'Dim dgCustomer as New DataGrid()
strConnection = "server=kresnadi-fonny;database=AGInventory;" & _
"uid=sa;password=kresnadi"

strSQL = "Select * from tblCustomer;"

objConnection = new SQLConnection(strConnection)
objAdapter = New SQLDataAdapter(strSQL, objConnection)

objAdapter.Fill(objDataSet, "tblCustomer")

dgCustomer.DataSource = objDataSet.Tables("tblCustomer").DefaultView
dgCustomer.DataBind()

End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" runat="server" Font-Bold="True"
Font-Size="X-Large" Font-Names="P22 Tai Chi" Height="81px" Width="366px">Asia
Gallery</asp:label><br>
<br>
<br>
<table>
<tr>
<td><asp:datagrid id="dgCustomer" runat="server"></asp:datagrid></td>
</tr>
</table>
</form>
</body>
</HTML>

The problem arises when I use asp.net built in component, such as
SQLDataAdapter, SQLConnection, DataSet, and DataGrid. I drag the table name
from Server Explorer and it generates SQLDataAdapter and SQLConnection
automatically. Then, I add DataSet and DataGrid. The Datasource of datagrid,
I points to the dataset. I also assigns the datamember.
Then, when on page load, I type this function:

DataSet21.Clear()
SqlDataAdapter1.Fill(DataSet21)

When I run the code, it displays blank page. It does not even generate error
message.

Please help. Thanks.
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top