Results 1 to 5 of 5

Thread: Datagrid Question

  1. #1

    Thread Starter
    Member spencem5's Avatar
    Join Date
    Apr 2005
    Posts
    38

    Datagrid Question

    One quick question... datagrids.
    I have my output looking the way I want and it now prints to the datagrid fine but my datagrid isn't listing first entry, starts with the second. It's like the first row isn't being read but the rest print fine. Did I forget something?

    Thanks a ton,
    M

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Datagrid Question

    Show us the datagrid's code and the codebehind for your datagrid's binding.

  3. #3

    Thread Starter
    Member spencem5's Avatar
    Join Date
    Apr 2005
    Posts
    38

    Re: Datagrid Question

    Here's what I had...

    sqlcon.Open()
    Dim drManagers As SqlDataReader = cmdGetManagers.ExecuteReader
    While drManagers.Read
    dgrid_ViewAllUsers.DataSource = drManagers
    dgrid_ViewAllUsers.DataBind()
    End While
    drManagers.Close()
    sqlcon.Close()

    sqlcon is my connection string and cmdGetManagers is my SQL Command. I'm trying to figure out why the first line in my datagrid is left out. The datagrid looks fine just that first row is showing up. The first row in my datagrid is actually the second row in my table. Any help would be much appreciated.

    Thanks,
    M

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Datagrid Question

    You don't need to do a while drManagers.Read the databinding will handle that.

    Try:
    Code:
    sqlcon.Open()
    Dim drManagers As SqlDataReader = cmdGetManagers.ExecuteReader
    dgrid_ViewAllUsers.DataSource = drManagers
    dgrid_ViewAllUsers.DataBind()
    drManagers.Close()
    sqlcon.Close()
    Calling drManagers.Read actually moves to the next record in the DataReader hence the missing first record.

    HTH

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  5. #5

    Thread Starter
    Member spencem5's Avatar
    Join Date
    Apr 2005
    Posts
    38

    Re: Datagrid Question

    Thanks for the feedback...
    That was the problem that was screwing me up. Haven't been programming for a few years and holy cow am I rusty. Thanks again for the help.

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