Hi Everyone,
I would like to know how to make a DataView global to a particular form.
The DataView is currently created and returned from a function within a public class residing in another .vb module.
All help will be appreciated. Thanks.
Truly,
Emad
Here's what the code in the other .vb module looks like:
Imports System.Data.OleDb
Public Class dbUtilities
' Setup the Connection string.
'-----------------------------
Dim strConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Emad's Section\Development\Visual Studio\Projects\ISGL School Application\" & _
"ISGL School Application\iap1.mdb"
' Create and return a DataView based on SQL passed to this function.
'-------------------------------------------------------------------
Public Function GetDataView(ByVal strSqlStatement As String) As DataView
' Declare a DataSet.
'-------------------
Dim objDataSet As New DataSet
' Declare a DataAdapter.
'-----------------------
Dim objDataAdapter As New OleDbDataAdapter(strSqlStatement, strConnectionString)
' Populate the Dataset with data.
'--------------------------------
objDataAdapter.Fill(objDataSet, "Attendance Data")
' Populate the DataView.
'-----------------------
Dim objDataView = New DataView(objDataSet.Tables(0))
Return objDataView
End Function
End Class
In my form this calls the function to return the DataView:
Private Sub RadioButtonNotAbsent_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButtonNotAbsent.CheckedChanged
Dim strFilter As String = "Absent = False"
If RadioButtonNotAbsent.Focus = True And RadioButtonNotAbsent.Checked = True Then
' objDataView.RowFilter = strFilter
DataGridViewAttendance.DataSource = objDatabaseUtilities.GetDataView(strAttendanceAttendedSelectStatement)
End If
End Sub
I would like to make objDataView global so I can use the RowFilter instead of doing a new DataSet every time the user clicks on this RadioButton.