|
-
Jun 28th, 2005, 03:38 AM
#1
Thread Starter
Junior Member
My datagrid didn't show data,why?please see my code.
I use asp.net and sql server 2000
Problems are:
I debug my web page but datagrid control didn't show any data from my database. and if i would like to create add, delete update and search button for datagrid, please give me a advices or show me...
Thanks
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Data" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Mypage.aspx.vb" Inherits="Myproject.Mypage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Mypage</title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'declarations
Dim conLath As SqlConnection
Dim cmdLath As SqlCommand
Dim rdrLath As SqlDataReader
conLath = New SqlConnection( _
"server=local;uid=;pwd=; " & _
"database=MySQLDB")
conLath.Open
cmdLath = New SqlCommand ( _
"select field1,field2 from MyTable", _
conLath)
rdrLath = cmdLath.ExecuteReader
gridLath.DataSource = rdrLath
gridLath.DataBind
rdrLath.Close
cmdLath.Dispose
conLath.Close
End Sub
</script>
<html>
<head>
<title>Test</title>
</head>
<asp ataGrid id="gridLath" runat="server"></asp ataGrid>
</body>
</html>
-
Jun 28th, 2005, 06:50 AM
#2
Member
Re: My datagrid didn't show data,why?please see my code.
 Originally Posted by wattha
Code:
<HTML>
<HEAD>
<title>Mypage</title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'declarations
Dim conLath As SqlConnection
Dim cmdLath As SqlCommand
Dim rdrLath As SqlDataReader
conLath = New SqlConnection( _
"server=local;uid=;pwd=; " & _
"database=MySQLDB")
conLath.Open
cmdLath = New SqlCommand ( _
"select field1,field2 from MyTable", _
conLath)
rdrLath = cmdLath.ExecuteReader
gridLath.DataSource = rdrLath
gridLath.DataBind
rdrLath.Close
cmdLath.Dispose
conLath.Close
End Sub
</script>
<html>
<head>
<title>Test</title>
</head>
<body>
<asp:DataGrid id="gridLath" runat="server"></asp:DataGrid>
</body>
</html>
a) You are missing a <body> tag after the </head> tag.
b) You are writing "Server=local" in the connection string. Replace local with the actual server name or if the SQL server is on the same machine then you could use "Server=(local)"
Just to clarify are you getting a blank page or an error message ?
Nikhil Aggarwal

-
Jun 28th, 2005, 10:37 PM
#3
Thread Starter
Junior Member
Re: My datagrid didn't show data,why?please see my code.
hi, Nikhil Aggarwal
Thanks but my problem is My page can debug not error appear, The other controls appear on page but just data grid didn't and not shown any data from database.
And i defined exaclty the server name, like wattha, if i would like to copy this project and Database files to open on another computer , It's may be error?? because of conflict server name????
-
Jun 30th, 2005, 02:34 AM
#4
Thread Starter
Junior Member
Re: My datagrid didn't show data,why?please see my code.
Hi,
I use datagrid when debug the page, Every controls are display normally except datagrid. It's not show any data from database, No error message appear, why & what wrong on my code?
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Myweb.aspx.vb" Inherits="Myproj.Myweb" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Myweb</title>
<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("server=(local)\NetSDK;database=MyDB;Trusted_Connection=yes")
MyCommand = New SqlDataAdapter("select * from MyTable", MyConnection)
DS = new DataSet()
MyCommand.Fill(ds, "MyTable")
MyDataGrid.DataSource=ds.Tables("MyTable").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp ataGrid id="MyDatagrid" runat="server" Width="700" BackColor="#ccccff" BorderColor="black"
ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
EnableViewState="false" style="Z-INDEX: 112; LEFT: 248px; POSITION: absolute; TOP: 184px" />
</form>
</body>
</HTML>
-
Jul 10th, 2005, 07:57 PM
#5
Junior Member
Re: My datagrid didn't show data,why?please see my code.
can you use a sqlcommand against mySQL. shouldn't you be using oledb?
-
Jul 11th, 2005, 12:37 AM
#6
Hyperactive Member
Re: My datagrid didn't show data,why?please see my code.
-
Jul 11th, 2005, 10:53 AM
#7
PowerPoster
Re: My datagrid didn't show data,why?please see my code.
1. I would suggest you use the Code Behind files to actully write the VB code instead of the aspx. page.
2. Check if the dataset actually returns any rows. If it returns ZERO, then the datagrid wont be displayed.
-
Jul 11th, 2005, 12:16 PM
#8
Hyperactive Member
Re: My datagrid didn't show data,why?please see my code.
I agree, it is so much easier, and cleaner looking by writing in codebehind rather than the aspx...
-
Jul 11th, 2005, 12:47 PM
#9
Re: My datagrid didn't show data,why?please see my code.
This maybe a stupid question, but I'll ask anyways, since it's the only thing that stands out to me: Can you bind a DataREADER to objects? Not only that, but it's defined within the Form_Load event, so that when it's done, it's going to fall out of scope and no longer be available.....
Tg
-
Jul 11th, 2005, 12:48 PM
#10
Re: My datagrid didn't show data,why?please see my code.
Never mind, I see now that it's been changed to a Dataset.... but I'd still have concerns that the DS variable is falling out of scope.
Tg
-
Jul 11th, 2005, 01:04 PM
#11
PowerPoster
Re: My datagrid didn't show data,why?please see my code.
but I'd still have concerns that the DS variable is falling out of scope.
I dont see where?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|