Query returns nothing

Discussion in 'ASP .Net' started by Bijoy Naick, Jan 15, 2004.

  1. Bijoy Naick

    Bijoy Naick Guest

    I am new to asp.net and having some trouble with a page.. First, here is
    the code.. The script section goes in the head. The body contains the
    datagrid line..

    <script language="vb" runat="server">
    Sub Page_Load(Source as Object, E As EventArgs)
    Dim myConnection as SqlConnection
    Dim myCommand as SqlCommand
    Dim myReader as SqlDataReader
    Dim sql as String
    Dim connStr as String

    sql = "SELECT * FROM Shippers"


    myConnection = New SqlConnection(connStr)

    myCommand = New SqlCommand(sql, myConnection)
    myReader = myCommand.ExecuteReader()

    theList.DataSource = myReader
    End Sub

    followed by

    <asp:DataGrid ID="theList" runat="server"/>

    My problem is that when the code executes, the datagrid is empty. There
    are no error messages. I knwo for a fact that the Shippers table
    contains a few records. The dotNetUser account exits in SQL Server and
    has owner privs on the Northwind database..

    What am i doing wrong?
    Bijoy Naick, Jan 15, 2004
    1. Advertisements

  2. Bijoy Naick

    ONIL@ Guest

    Hi, Bijoy !
    Try this, could work!

    a) Establish your solution configurations to debug
    b) set a debug point in the sql = "SELECT * FROM Shippers"
    b) debug your code since this point and thats it! (I know this sound like a
    joke but believe me, it works..)

    ONIL@, Jan 15, 2004
    1. Advertisements

  3. Bijoy Naick

    Prince Guest

    I believe the DataGrig control will not render unless
    you've bound some columns to it.


    <asp:DataGrid ID="shoppingCartDataGrid" Runat="server"

    <asp:BoundColumn DataField="ProductName"
    HeaderText="Product Name"></asp:BoundColumn>


    That should work.

    -- Prince
    Prince, Feb 1, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.