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"

    connStr="server=localhost;uid=dotNetUser;pwd=myPasswd;database=Northwind
    "

    myConnection = New SqlConnection(connStr)
    myConnection.Open()

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

    theList.DataSource = myReader
    theList.DataBind()
    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
    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..)

    Greetings.
    ONil@.
    MX.
     
    ONIL@, Jan 15, 2004
    #2
    1. Advertisements

  3. Bijoy Naick

    Prince Guest

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

    ex.

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

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

    </asp:DataGrid>

    That should work.

    -- Prince
     
    Prince, Feb 1, 2004
    #3
    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.