Solved

Filling Grid.. DataTable, DataReader???

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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