datagrid data not showing

Discussion in 'ASP .Net Datagrid Control' started by Brent Burkart, Jan 16, 2004.

  1. I have a datagrid that simply shows readonly data that i pull using sql.
    This was working fine and one day it stopped working.

    It shows the headers, but no data. Can anyone point me in the right
    direction? I am stuck.
    Brent Burkart, Jan 16, 2004
    1. Advertisements

  2. Brent Burkart

    Alvin Bruney Guest

    first check to see if all your handlers are mapped correctly
    then check to see if data is being returned
    Alvin Bruney, Jan 16, 2004
    1. Advertisements

  3. I have checked this and I have hooked up Profiler to see if my query is
    working. Not sure how to check for the data being returned. I assume it is
    since I am checking for present data in a Sqldatareader.

    Here is my code

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here



    End Sub

    Sub get_data()

    myConnection = New SqlConnection("x")


    myCommand = New SqlCommand("select
    borrower, propchar, loan where loan.loanid = borrower.loanid and loan.loanid
    = propchar.loanid and borrower.borrowercount = 1 and BSOCSECNO = '" &
    Trim(Request.QueryString("SSN")) & "'", myConnection)

    myDatareader = myCommand.ExecuteReader()

    End Sub

    Sub Populate_Fields()

    If myDatareader.Read Then

    myDataGrid.DataSource = myDatareader



    Label1.Text = "No data found corresponding to an SSN of " &

    End If



    myDatareader = Nothing

    myConnection = Nothing

    myCommand = Nothing

    End Sub
    Brent Burkart, Jan 16, 2004
  4. I am confused because as you can see in the code, I check to see if there is
    data in my datareader, if there is then I databind to the datasource, if not
    I display a message. However, the header of the datagrid shows up which
    leads me to believe it thinks there is data, but it is just not showing.
    Brent Burkart, Jan 16, 2004
  5. Brent Burkart

    Alvin Bruney Guest

    you have a couple of things wrong here
    you should be using a dataset here, a datareader is typically used for
    speedy access to single values
    also, an exception in the datareader will leak memory and result in a
    blocked datareader which is why it is better in your circumstance to use a
    dataset. there is ample code on the net to show you how to do this. if you
    insist on using a datareader, you need at least a try finally block or at
    most some exception handling to catch an error and call close on the
    datareader, then set it to null
    also, to find the values in the datareader, you will need to loop thru the
    reader to extract the values
    string val1 = myDatareader[0].ToString()
    string val2 = myDatareader[1].ToString() etc...
    Alvin Bruney, Jan 17, 2004
  6. Brent Burkart

    Alex Guest

    you should be using a dataset here, a datareader is typically used for
    NOT true! DataReader is simply forward-only access to the data. What you're
    talking about (single values) is ExecuteScalar!
    Most of the time DataReader is the way to go if you only want to display
    Alex, Jan 17, 2004
  7. Brent Burkart

    Alvin Bruney Guest

    Yes, that's correct. My bad.

    This makes my post technically inaccurate. Hope OP is aware of that.
    Alvin Bruney, Jan 17, 2004
  8. Brent Burkart

    ben Guest

    might not be a techie solution but i have had this problem a few times

    -make sure the datagrid is declared(protected System.Web.UI.... datagrid1)
    -make sure that all the components are initialized in the web form generated code

    hope this a newbie...
    ben, Jan 21, 2004
  9. I am an newbie also, but I am also kind of an idiot. The reason data was
    not showing was because I was checking for data before I displayed the
    datagrid. When I did the check (, I used up the first and
    only record, which left no more records for my datagrid.
    Brent Burkart, Jan 23, 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.