Home All Groups Group Topic Archive Search About

Filling a DataGrid with a DataSet

Author
14 Sep 2006 12:10 AM
WayneM
I have compact framework app that I was trying to test out on a windows form,
but I cannot get past the very first step of simply filling a DataGrid from a
DataSet.  My code is

Dim sqlStmt As String = "Select VendorName, StartWeek from InventorySchedule
Where FinishDate is Null and StartWeek<'" & Now & "'"
        Dim cmdDB As New SqlCommand(sqlStmt, connDB)
        Dim dgridTarget As New DataGrid
        Dim adapter As New SqlDataAdapter()
        Dim ds As New DataSet      
             '   create the table style in the grid
            Dim dgtsStyle As DataGridTableStyle
            Dim dgtsColumn As DataGridTextBoxColumn
            dgtsStyle = New DataGridTableStyle

            '   set the tablestyle mapping to the table name
            With dgtsStyle
                .MappingName = "VendorsToCount"
            End With

            dgtsColumn = New DataGridTextBoxColumn
            dgtsColumn.MappingName = "VendorName"
            dgtsColumn.HeaderText = "VName"
            dgtsColumn.Width = 100
            dgtsStyle.GridColumnStyles.Add(dgtsColumn)

            dgtsColumn = New DataGridTextBoxColumn
            dgtsColumn.MappingName = "StartWeek"
            dgtsColumn.HeaderText = "Start"
            dgtsColumn.Width = 100
            dgtsStyle.GridColumnStyles.Add(dgtsColumn)

            '   add the style to the datagrid
            dgridTarget.TableStyles.Add(dgtsStyle)

            '   open the connection
            connDB.Open()

            adapter.SelectCommand = New SqlCommand(sqlStmt, connDB)
            adapter.Fill(ds)

            dgridTarget.Visible = True
            dgridTarget.SetDataBinding(ds, "VendorsToCount")

I need to use the Datagrid, because it is supported on the CF, where this
app will be deployed.

I am simply creating a dataset and binding it to the Datagrid.  What am I
missing here? 

Thanks for any help,

WayneM

Author
14 Sep 2006 6:24 AM
Spam Catcher
=?Utf-8?B?V2F5bmVN?= <Way***@discussions.microsoft.com> wrote in
news:DD305AF7-0758-4E1B-94A7-0B72CED31BCE@microsoft.com:

> Dim sqlStmt As String = "Select VendorName, StartWeek from
> InventorySchedule Where FinishDate is Null and StartWeek<'" & Now &
> "'"

Slightly OT, but you should use SQLParameters to prevent a SQL injection
attack.