Filling a DataGrid with a DataSet

G

Guest

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top