VB.NET - Set the DataSource of a DataGrid



Sets the DataSource of a DataGrid

'Assembly: System.Windows.Forms.dll
'Assembly: System.Data.dll
'Assembly: System.Data.SqlServerCe.dll
'Assembly: System.Xml

'Namespace: Microsoft.VisualBasic
'Namespace: System.Windows.Forms
'Namespace: System.Data
'Namespace: System.Data.SqlServerCe

'Dim datagrid AS DataGrid

Private Sub SetDataSource()
    Dim sqlConn As System.Data.SqlServerCe.SqlCeConnection
    Dim sqlDS As New DataSet
    
    ' It is assumed that there is a SQL Server Mobile Edition database
    ' named test.sdf, and that the database has a table named
    ' People. These should be modified to fit your application.
    sqlConn = New SqlCeConnection(DataSourceName)
    
    ' Select everything from a database named People on the SqlCeConnection sqlConn.
    Dim sqlDA As New SqlCeDataAdapter(string, sqlConn)
    
    ' Fill the DataTable People within the DataSet sqlDS.
    sqlDA.Fill(sqlDS, table)
    
    ' Set the DataSource as the People table in the DataSet.
    datagrid.DataSource = sqlDS.Tables(table)
End Sub

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.