Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Filling Grid.. DataTable, DataReader???

Posted on 2009-04-03
4
Medium Priority
?
1,106 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
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
TeamEnova earned 1000 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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

972 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