Results 1 to 11 of 11

Thread: My datagrid didn't show data,why?please see my code.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    20

    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>


    <aspataGrid id="gridLath" runat="server"></aspataGrid>
    </body>
    </html>

  2. #2
    Member Nikhil Aggarwal's Avatar
    Join Date
    Jun 2005
    Location
    New Delhi, India
    Posts
    36

    Re: My datagrid didn't show data,why?please see my code.

    Quote 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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    20

    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????

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    20

    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">
    <aspataGrid 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>

  5. #5
    Junior Member
    Join Date
    Jun 2002
    Location
    Midwest
    Posts
    27

    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?

  6. #6
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    Re: My datagrid didn't show data,why?please see my code.

    you cannot, get the mysql oledb driver:

    http://dev.mysql.com/downloads/connector/net/1.0.html

  7. #7
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    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.

  8. #8
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    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...

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    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
  •  



Click Here to Expand Forum to Full Width