Solved

Filling Grid.. DataTable, DataReader???

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now