Solved

Filling Grid.. DataTable, DataReader???

Posted on 2009-04-03
4
1,089 Views
Last Modified: 2012-05-06
Hi EE,
I fill a lot of grids (fpSpread) in my program.  
I fill all of these grids with every field in the table so that it is Select * from table
Now I am trying to fill a grid, using the same code, but my select statement does not include all the fields in the table.  
There is a record in my table, and it shows there is a record when I check dataset tables, but the grid won't fill.  
Please tell me what I am doing wrong and provide an example.  
Thanks,

Function FillSpread() As DataTable
        Dim ds As New DataSet
 
        If DatabaseToUse() = BizObjs.DBType.Access Then
 
 
            Dim dc As New OleDb.OleDbConnection(ConnectionString)
            Dim da As New OleDb.OleDbDataAdapter(SelectStatement, dc)
 
            Try
 
                da.Fill(ds)
                dc.Close()
                da.Dispose()
 
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                dc.Close()
 
            End Try
        End If
 
        Return GenerateDataTable(ds)
'Returns as datasource to the grid
 
    End Function

Open in new window

0
Comment
Question by:Sheritlw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
TeamEnova earned 250 total points
ID: 24066098
Sheritlw,
If you are sure that the ds is actually getting returned (assuming you are putting a break in to see the ds), and you call the gridview.databind after setting the gridview.datasource to the ds, then the only other thing I can come up with quickly is that your dataset is dumping prior to binding to the gridview.

Where are you seeing the fact that the ds has records in it?
0
 
LVL 24

Assisted Solution

by:Jeff Certain
Jeff Certain earned 250 total points
ID: 24067622
1. You can simplify your code by filling a DataTable directly instead of filling the DataSet.
2. Could you post your SELECT statement? Sometimes, especially with Access, you'll run into problems where the naming of a column conflicts with a database keyword.
3. Could you show the code where you're binding to the grid?
0
 

Author Comment

by:Sheritlw
ID: 24070176
Hi I appreciate your help,

My select statement is as follows...

str = "Select ContactID, CompanyID, ContactName, emailAdd, PhoneTypeID1, " _
            & " PhoneNumb1, PhoneTypeID2, PhoneNumb2, PhoneTypeID3, " _
            & " PhoneNumb3, PhoneTypeID4, PhoneNumb4 from contacts where " _
            & " CompanyID = " & miCompanyID & " Order by " _
            & " ContactName"

I check that there is a record in this procedure
Public Shared Function GenerateDataTable(ByVal ds As DataSet) As DataTable
        If ds.Tables.Count > 0 Then
            Return ds.Tables(0)
        Else
            Return Nothing
        End If
    End Function

and again, the following is my fill procedure.

    Function FillSpread() As DataTable
        Dim ds As New DataSet

        If DatabaseToUse() = BizObjs.DBType.Access Then

            Dim dc As New OleDb.OleDbConnection(ConnectionString)
            Dim da As New OleDb.OleDbDataAdapter(SelectStatement, dc)

            Try

                da.Fill(ds)
                dc.Close()
                da.Dispose()

            Catch ex As Exception
                MessageBox.Show(ex.Message)
                dc.Close()

            End Try
        End If

        Return GenerateDataTable(ds)

    End Function
0
 

Author Comment

by:Sheritlw
ID: 24070363

Whoops!  I was hooking it up to the wrong grid.  Code works fine.
I am splitting the point between the two of you.
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question