Link to home
Start Free TrialLog in
Avatar of sainavya1215
sainavya1215

asked on

Remoting unbound comboBox Error

Hi,

I have a unbound comboBox which returns dataset via a function to the client and combo is populated with values from database.
The following code works fine on single machine but when tested on remote machine

it throws an error at the last statement in client side code which is


 
            Dim cItem As New cComboItem(dr)

Error "The type system.XML.XMLBoundElement in assembly system.data, Version=1.0.5000.0,culture=Neutral,PublicKeyToken=b77a5c561934e089 is not marked as serializable"



here is the code:

client side
=====
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Obj As New cComboItem
        Dim ds As New DataSet
        ds = Obj.ReturnDataSet()

        Dim dt As DataTable
        dt = ds.Tables(0)

        Dim dr As DataRow
        For Each dr In dt.Rows
            Dim cItem As New cComboItem(dr)  ======ERROR OCCOURS AT THIS POINT============
            CboEmployee.Items.Add(cItem)
        Next




    End Sub

    Private Sub CboEmployee_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboEmployee.SelectedIndexChanged
        Dim cItem As cComboItem = CType(CboEmployee.SelectedItem, cComboItem)
        MessageBox.Show(cItem.GetId)

    End Sub


DLL
=======================

Imports System.Data.SqlClient
Imports System.Data

''''Commented <serializable()>


Public Class cComboItem

    Public mdr As DataRow
    Public Sub New(ByVal dr As DataRow)
        mdr = dr
    End Sub
    Public Sub New()

    End Sub
    Public Overrides Function ToString() As String
        Return mdr("firstname")
    End Function

    Public Function GetId()
        Return mdr("employeeid")
    End Function


    Public Function ReturnDataSet() As DataSet

        Dim myConnection As SqlClient.SqlConnection
        Dim myDataAdapter As SqlClient.SqlDataAdapter
        Dim myDataSet As DataSet

        myConnection = New SqlConnection("server=(local);database=northwind;Trusted_Connection=SSPI;")


        myDataAdapter = New SqlDataAdapter("SELECT * FROM employees", myConnection)
        myDataSet = New DataSet
        myDataAdapter.Fill(myDataSet, "Employees")
        Return myDataSet

    End Function

End Class
ASKER CERTIFIED SOLUTION
Avatar of amos_olson
amos_olson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sainavya1215
sainavya1215

ASKER

hi,
I will try this out and keep u posted within 2 days from now

Thx
Thanks it works........sorry for the late reply ....but there is a small prob lets say there at 10 records it displays all the 10 records in comboBox .....works fine
Now if u go and delete some records in sql server and reload the application it still shows 10 records. why is this happening is there any change in code needed?
Since the code simple gets records from the database and returns them to the presentation layer, any change to the underlying data should definately be reflected in the combo box.  A few things come to mind though:

1. It's possible you might be changing the wrong database.  This has happened to me a few times since I'm running several different databases at once.  I know it seems like a silly thing but it's worth looking into...

2. You might have your application configured to do some caching at some level, which might make the application reuse old data rather than query new data.

3.  To find out, modify your cComboItem classes ToString method to look like this:
    Public Overrides Function ToString() As String
        Return mdr("firstname") & "test"
    End Function

This should cause "test" to be added to the end of each name in the combo box.  If "test" appears at the end, then you're probably modifying the wrong data source.  If it doesn't then your front end aspx page must be caching it's output.
thanks it works .......