Solved

Filling Grid.. DataTable, DataReader???

Posted on 2009-04-03
4
1,078 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

939 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now