Question 2 Listboxes, One showing data normally, the second showing System.Data.DataRowView

acidflash

Active member
Joined
Oct 23, 2008
Messages
29
Programming Experience
1-3
Hello All,

I am writing a small program and i have recently encountered a problem that i cant seem to find a solution to. I have 2 listboxes on a single page, and I am trying to populate both of them according to certain SQL commands. When I put one infront of the other, the one in front works, when I switch them, again the one infront works. The one that always comes later always displays "System.Data.DataRowView" instead of the entry its supposed to. Here is the code.

VB.NET:
Private Sub Service_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ClientsConnection.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =" & Application.StartupPath & "\SS Solutions.mdb"
        ClientsConnection.Open()
        ClientsString = "SELECT * FROM Clients"
        ClientsDA = New OleDb.OleDbDataAdapter(ClientsString, ClientsConnection)
        ClientsDA.Fill(ClientsDS, "ClientsMain")
        ClientsInc = 0
        PendingString = "SELECT * FROM Clients WHERE Installed ='Not Installed'"
        PendingDA = New OleDb.OleDbDataAdapter(PendingString, ClientsConnection)
        PendingDA.Fill(PendingDS, "PendingMain")
        PendingInc = 0
        Dim Caption As New ToolTip()
        ' Set up the delays for the ToolTip.
        Caption.AutoPopDelay = 5000
        Caption.InitialDelay = 100
        Caption.ReshowDelay = 500
        ' Force the ToolTip text to be displayed whether or not the form is active.
        Caption.ShowAlways = True
        ' Set up the ToolTip text for the Button and Checkbox.
        Caption.SetToolTip(Me.bAddClient, "Add client")
        Caption.SetToolTip(Me.bRemoveClient, "Remove client")
        Caption.SetToolTip(Me.bSearch, "Search")
        Caption.SetToolTip(Me.bReport, "Report")
        DateOfCall.Text = System.DateTime.Today
        dt = ClientsDS.Tables("ClientsMain")
        dt2 = PendingDS.Tables("PendingMain")
        lstClients.DataSource = dt
        lstPending.DataSource = dt2
        lstClients.DisplayMember = "FirstName"
        lstClients.DataBindings.Add("Name", ClientsConnection, "FirstName")
        lstPending.DisplayMember = "FirstName"
        lstPending.DataBindings.Add("FirstName", ClientsConnection, "FirstName")
        CalculateAccessPoints()
        CalculateInstalled()
        CalculatePending()
        lblNumOfUsers.Text = dt.Rows.Count
        lblTotalInstalled.Text = TotalInstalledUsers
        lblTotalPending.Text = TotalPendingUsers
        lblNumOfAp.Text = TotalAccessPoints
    End Sub

Any help is much appreciated seeing as I am lost. I have tried to open several connections closing one in front of another to populate the second listbox but to no avail. I have also tried to almost every solution I could find online, including ones regarding "ValueMember" etc. No avail. Again the problem is that the listbox code that comes first always displays properly, the one that comes second in the code always displays "System.Data.DataRowView" and I am not quite sure why.

acidflash
 
Solved,

Thanks to some help from IRC, the solution to the problem was to remove the code for lstClients.DataBindings.Add and lstPending.DataBindings.Add. There is no need for it. Thank you to those who helped.

acidflash
 
I'd have started by advising you read the DW3 link in my siganture, section "Creating a Simple Data App"
It describes a way of doing data access that is much easier, faster and more secure than you have here. Adding 2 listboxes with the relevant contents would also have been a matter of drag and drop.. Essentially using the visual designer for some aspects of your program ensures problems like these never happen because the designer does things like databindings in the right way
 
Back
Top