By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,198 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,198 IT Pros & Developers. It's quick & easy.

Filling a DataGrid with a DataSet

P: n/a
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
Sep 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
=?Utf-8?B?V2F5bmVN?= <Wa****@discussions.microsoft.comwrote in
news:DD**********************************@microsof t.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.

Sep 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.