0
Answer

Dataview sort method with multitables

Dave Amega

Dave Amega

12y
1.4k
1
I have created a combo box and a listview application using the combo box to fetch data and display result in the listview. When I run the application I get an error message "No value given for one or more parameters". When I clicke on the ok buttom it comes out with Exception error msg "DataTable must be set prior to using DataView." directiing me to "

objDataView.Sort =


Imports

System.Data.OleDb

Imports

MysecuritData

Imports

System.IO

Public
















Class frmCulpritOffenceDetailsDim dsCulprit As New DataSetDim objDataSet As New DataSetDim daCulprit As New OleDbDataAdapterDim daOffence As New OleDbDataAdapterDim CulpritBindingSource As New BindingSourceDim Culprit As CulpritDim CulpritView As DataViewDim offenceView As DataViewDim tblOffenceDataTable As New DataTableDim CulpritDataTable As DataTablePrivate Sub frmOffenceMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LoadRemoveHandler cboCulprits.SelectedIndexChanged, AddressOf cboCulprits_SelectedIndexChangedMe.CreateDataProviderObjects()'dvOffence = New DataView


'Dim dvOffence As DataView = New DataView(DsOffence.Tables("tblOffence"))




Me.FillTables()Me.BindCulpritComboBox()' CulpritView = New DataView(dsCulprit.Tables("Culprit"))

offenceView =




New DataView(objDataSet.Tables("tblOffence"))Me.GetOffences()AddHandler cboCulprits.SelectedIndexChanged, AddressOf cboCulprits_SelectedIndexChangedEnd Sub




CulpritCommand.Connection = conn


Private Sub CreateDataProviderObjects()Dim conn As OleDb.OleDbConnection = SecurityDB.GetConnection()Dim CulpritCommand As New OleDbCommandDim CulpritSelect As String = "SELECT CulpritID, LastName from Culprit ORDER BY Lastname"

CulpritCommand.CommandText = CulpritSelect

daCulprit.SelectCommand = CulpritCommand


OffenceCommand.Connection = conn


=

Dim OffenceCommand As New OleDbCommandDim OffenceSelect As String _"SELECT Description, OffenceDate, CulpritID, OffenceCode, OffenceType, LastJailed, NoOfTimesJailed, RelatedOffence FROM tblOffence"

OffenceCommand.CommandText = OffenceSelect

daOffence.SelectCommand = OffenceCommand


End Sub




CulpritCommand.Connection = conn


Private Sub FillTables()Dim conn As OleDb.OleDbConnection = SecurityDB.GetConnection()Dim CulpritCommand As New OleDbCommandDim CulpritSelect As String = "SELECT CulpritId, LastName from Culprit ORDER BY Lastname"

CulpritCommand.CommandText = CulpritSelect

daCulprit.SelectCommand = CulpritCommand


OffenceCommand.Connection = conn


=

Dim OffenceCommand As New OleDbCommandDim OffenceSelect As String _"SELECT Description, OffenceDate, CulpritID, OffenceCode, OffenceType, LastJailed, NoOfTimesJailed, RelatedOfence FROM tblOffence"

OffenceCommand.CommandText = OffenceSelect

daOffence.SelectCommand = OffenceCommand


Try

conn.Open()

daCulprit.MissingSchemaAction _

= MissingSchemaAction.AddWithKey

daCulprit.Fill(objDataSet,

daOffence.Fill(objDataSet,


MessageBox.Show(ex.Message)


"Culprit")"tblOffence")Catch ex As ExceptionFinally

conn.Close()


End Try


End Sub



.DataSource = objDataSet.Tables(

.DisplayMember =

Private Sub BindCulpritComboBox()With cboCulprits"Culprit")"LastName"

.ValueMember =

"CulpritID"


End With

cboCulprits.SelectedIndex = -1


End Sub



.Find(cboCulprits.SelectedValue)





Private Sub GetOffences()Dim CulpritRow As DataRow = objDataSet.Tables("Culprit").Rows _Dim objDataView = New DataView(objDataSet.Tables("tblOffence"))Select Case chkShowOffence.CheckedCase False

objDataView.RowFilter =

&

objDataView.Sort =

"CulpritID = " _CInt(cboCulprits.SelectedValue)"OffenceCode"

lblCount.Text = objDataView.Count &

& IIf(objDataView.Count = 1,


"tblOffence" _"", "s").ToStringCase True


' Dim objDataView = New DataView(objDataSet.Tables("tblOffence"))

objDataView.RowFilter =

&

objDataView.Sort =

"CulpritID = " _CInt(cboCulprits.SelectedValue)"OffenceType"

lblCount.Text = objDataView.Count &

& IIf(objDataView.Count = 1,


"tblOffence" _"", "s").ToStringEnd Select



lvOffence.Items.Clear()


row = dvtblOffence(i)


Dim row As DataRowViewFor i As Integer = 0 To dvtblOffence.Count - 1'lvOffence.Items.Add(row("OffenceID").ToString)

lvOffence.Items(i).SubItems.Add(row(

lvOffence.Items(i).SubItems.Add(


lvOffence.Items(i).SubItems.Add(row(

lvOffence.Items(i).SubItems.Add(row(

lvOffence.Items(i).SubItems.Add(row(

lvOffence.Items(i).SubItems.Add(row(

lvOffence.Items(i).SubItems.Add(row(

lvOffence.Items(i).SubItems.Add(row(



"Description").ToString)String.Format("{0:d}", _CDate(row("OffenceDate"))))"CulpritID").ToString)"OffenceCode").ToString)"OffenceType").ToString)"LastJailed").ToString)"NoOfTimesJailed").ToString)"RelatedOffence").ToString)Next


End Sub





Private Sub cboCulprits_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCulprits.SelectedIndexChangedMe.GetOffences()End Sub




Private Sub chkShowOffence_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)Me.GetOffences()End Sub




Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.ClickMe.Close()End Sub





Private Sub btnFindCulprit_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindCulprit.ClickDim findCulpritForm As New frmFindCulpritDim result As DialogResult = findCulpritForm.ShowDialog()If result = Windows.Forms.DialogResult.OK Then

cboCulprits.Text = Culprit.LastName.ToString

CulpritBindingSource.Clear()

CulpritBindingSource.Add(Culprit)


End If


End Sub



frmCulpritForm.addCulprit =

Private Sub btnAddCulprit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCulprit.ClickDim frmCulpritForm As New frmCulpritTrue



Dim result As DialogResult = frmCulpritForm.ShowDialogIf result = Windows.Forms.DialogResult.OK Then

cboCulprits.Text = Culprit.LastName.ToString

CulpritBindingSource.Clear()

CulpritBindingSource.Add(Culprit)


End If




End

Me.Hide()End Sub Class
"OffenceCode". Below is my code. I need someone to help me with where I am going wrong. Is a 3-tier application. The tables are Culprits and Offence. Thanks in advance