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.

Declare a field of type DataView in a form and assign a reference to it.

public class Form1 : Form
    Dim dv as DataView

    Sub SomeMethond_oR_Click_Event()
         dv=new dbUtilities().GetDataView("put_argument")
   End Sub
End Class

Hi adatapost.

It worked. Thanks for the help.

Looks like I need to lean about referencing.

Were you able to figure out why I could not update my database with the update command of the data adapter?

Truly,
Emad

Hi,

Please upload zip & database, do not include executable.

Hi adatapost,

Thanks for taking the time to look at my project.

I tried to upload it but the daniweb site is giving me errors when I try to upload the zip file.

Can you email me and I will reply with the zip file? I will try to see if daniweb allows me to send you a pm.

Truly,
Emad

Hi,

Just wanted to thank adapost for solving my original post on how to make a DataView global to a particular form.

Truly,
Emad

Hi Emad.

Rule says - Do not post asking for an answer to be sent to you via email or PM. Problems and their responses assist others who read them. Please do not email or PM forum staff with your support questions.

Hi adapost,

Ooops. Sorry,

I tried to upload but the site responds with a token ring error.

I can upload much of the project code if that's ok.

Truly,
Emad

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.