VB Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged If ListBox1.SelectedItems.Count = 0 Then Else Try Dim strConn_list As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=DATABASE;Integrated Security=True;User Instance=True" Dim objConn_list As New SqlClient.SqlConnection(strConn_list) Dim ds As New DataSet Dim da As SqlClient.SqlDataAdapter, dt As DataTable Dim dr As DataRow da = New SqlClient.SqlDataAdapter("SELECT license_id, product_name, company_name, po_number, date, user_licenses FROM licenses WHERE division_name=@Division", objConn_list) da.SelectCommand.Parameters.Add("@Division", ListBox1.SelectedItem) da.Fill(ds) ListView1.Items.Clear() 'Repeat for each table in the DataSet collection. For Each dt In ds.Tables 'Repeat for each row in the table. For Each dr In dt.Rows ListView1.Items.Add(dr("product_name")) ListView1.Items(0).SubItems.Add(dr("company_name")) ListView1.Items(0).SubItems.Add(dr("po_number")) ListView1.Items(0).SubItems.Add(dr("date")) ListView1.Items(0).SubItems.Add(dr("users_licenses")) Next Next Catch ex_list As Exception MsgBox(ex_list.Message & ". Conact RattleSoft for support.") End Try End If End Sub End Class
For some reason it keeps throwing this error:
No mapping exists from object type System.Data.DataRowView to a known managed provider native type.
On form load it gathers details from the database properly, but it also throws an error before the SelectedIndex is changed.




Reply With Quote