DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Dataview problem

  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Post Dataview problem

    I am working on a 3-tier application in vs2005. I have two tables offence, culprit. I created a combobox for culpritID to pull the culprits lastname that will show related offences in a listview all on the same form. When I run the application, I get an error message "No value given for one or more required parameters" when I click on the "OK" button , I get "Data table must be set prior to using Dataview and pointing to my objDataview.Sort = "OffenceCode". I thought I have done everything right yet still have this error msg. I do not know where I am going wrong. I have added the code below. Could someone help me please. Thanks for your support. Kingsoh
    Code:
    Imports System.Data.OleDb
    Imports MysecuritData
    Imports System.IO
    Public Class frmCulpritOffenceDetails
    
        Dim dsCulprit As New DataSet
        Dim objDataSet As New DataSet
        Dim daCulprit As New OleDbDataAdapter
        Dim daOffence As New OleDbDataAdapter
        Dim CulpritBindingSource As New BindingSource
        Dim Culprit As Culprit
        Dim CulpritView As DataView
        Dim offenceView As DataView
        Dim tblOffenceDataTable As New DataTable
        Dim CulpritDataTable As DataTable
    
        Private Sub frmOffenceMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            RemoveHandler cboCulprits.SelectedIndexChanged, AddressOf cboCulprits_SelectedIndexChanged
            Me.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_SelectedIndexChanged
    
        End Sub
        Private Sub CreateDataProviderObjects()
            Dim conn As OleDb.OleDbConnection = SecurityDB.GetConnection()
            Dim CulpritCommand As New OleDbCommand
            CulpritCommand.Connection = conn
            Dim CulpritSelect As String = "SELECT CulpritID, LastName from Culprit ORDER BY Lastname"
            CulpritCommand.CommandText = CulpritSelect
            daCulprit.SelectCommand = CulpritCommand
    
            Dim OffenceCommand As New OleDbCommand
            OffenceCommand.Connection = conn
            Dim OffenceSelect As String _
            = "SELECT  Description, OffenceDate, CulpritID, OffenceCode, OffenceType, LastJailed, NoOfTimesJailed, RelatedOffence FROM tblOffence"
            OffenceCommand.CommandText = OffenceSelect
            daOffence.SelectCommand = OffenceCommand
    
        End Sub
    
        Private Sub FillTables()
            Dim conn As OleDb.OleDbConnection = SecurityDB.GetConnection()
            'Dim CulpritCommand As New OleDbCommand
            'CulpritCommand.Connection = conn
            'Dim CulpritSelect As String = "SELECT CulpritId, LastName from Culprit ORDER BY Lastname"
            'CulpritCommand.CommandText = CulpritSelect
            'daCulprit.SelectCommand = CulpritCommand
    
            'Dim OffenceCommand As New OleDbCommand
            'OffenceCommand.Connection = conn
            'Dim 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, "Culprit")
                daOffence.Fill(objDataSet, "tblOffence")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                conn.Close()
            End Try
        End Sub
        Private Sub BindCulpritComboBox()
            With cboCulprits
                .DataSource = objDataSet.Tables("Culprit")
                .DisplayMember = "LastName"
                .ValueMember = "CulpritID"
            End With
            cboCulprits.SelectedIndex = -1
        End Sub
        Private Sub GetOffences()
            Dim CulpritRow As DataRow = objDataSet.Tables("Culprit").Rows _
             .Find(cboCulprits.SelectedValue)
    
    
    
            Select Case chkShowOffence.Checked
                Case False
                    Dim objDataView = New DataView(objDataSet.Tables("tblOffence"))
                    objDataView.RowFilter = "CulpritID = " _
                    & CInt(cboCulprits.SelectedValue)
                    objDataView.Sort = "OffenceCode"
                    lblCount.Text = objDataView.Count & " tblOffence" _
                                    & IIf(objDataView.Count = 1, "", "s").ToString
                Case True
                    Dim objDataView = New DataView(objDataSet.Tables("tblOffence"))
                    objDataView.RowFilter = "CulpritID = " _
                         & CInt(cboCulprits.SelectedValue)
                    objDataView.Sort = "OffenceType"
                    lblCount.Text = objDataView.Count & " tblOffence" _
                                    & IIf(objDataView.Count = 1, "", "s").ToString
            End Select
           
            Dim row As DataRowView
            lvOffence.Items.Clear()
            For i As Integer = 0 To dvtblOffence.Count - 1
                row = dvtblOffence(i)
                'lvOffence.Items.Add(row("OffenceID").ToString)
                lvOffence.Items(i).SubItems.Add(row("Description").ToString)
                lvOffence.Items(i).SubItems.Add(String.Format("{0:d}", _
                  CDate(row("OffenceDate"))))
                lvOffence.Items(i).SubItems.Add(row("CulpritID").ToString)
                lvOffence.Items(i).SubItems.Add(row("OffenceCode").ToString)
                lvOffence.Items(i).SubItems.Add(row("OffenceType").ToString)
                lvOffence.Items(i).SubItems.Add(row("LastJailed").ToString)
                lvOffence.Items(i).SubItems.Add(row("NoOfTimesJailed").ToString)
                lvOffence.Items(i).SubItems.Add(row("RelatedOffence").ToString)
    
    
            Next
    
        End Sub
    
        Private Sub cboCulprits_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCulprits.SelectedIndexChanged
    
            Me.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.Click
            Me.Close()
        End Sub
    
        Private Sub btnFindCulprit_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindCulprit.Click
            Dim findCulpritForm As New frmFindCulprit
            Dim 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
    
        Private Sub btnAddCulprit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCulprit.Click
            Dim frmCulpritForm As New frmCulprit
            frmCulpritForm.addCulprit = True
            Dim result As DialogResult = frmCulpritForm.ShowDialog
            If result = Windows.Forms.DialogResult.OK Then
                cboCulprits.Text = Culprit.LastName.ToString
                CulpritBindingSource.Clear()
                CulpritBindingSource.Add(Culprit)
            End If
            Me.Hide()
        End Sub
    
    
    End Class
    Last edited by Hack; 08-19-2012 at 08:32 AM. Reason: Added Code Tags

Similar Threads

  1. Problem with DataView Sort
    By gangleader in forum ASP.NET
    Replies: 3
    Last Post: 10-11-2006, 11:09 AM
  2. Help with DataView.RowFilter
    By software_develo in forum .NET
    Replies: 1
    Last Post: 08-16-2006, 12:41 PM
  3. Dataview & Relationships
    By john83 in forum .NET
    Replies: 3
    Last Post: 05-20-2005, 01:33 PM
  4. DataGrid and DataView
    By Gori in forum .NET
    Replies: 3
    Last Post: 03-17-2005, 09:26 AM
  5. DataView problem
    By Al in forum ASP.NET
    Replies: 0
    Last Post: 05-02-2003, 05:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center