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,P ublicKeyTo ken=b77a5c 561934e089 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(cIte m)
Next
End Sub
Private Sub CboEmployee_SelectedIndexC hanged(ByV al sender As Object, ByVal e As System.EventArgs) Handles CboEmployee.SelectedIndexC hanged
Dim cItem As cComboItem = CType(CboEmployee.Selected Item, cComboItem)
MessageBox.Show(cItem.GetI d)
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=(loc al);databa se=northwi nd;Trusted _Connectio n=SSPI;")
myDataAdapter = New SqlDataAdapter("SELECT * FROM employees", myConnection)
myDataSet = New DataSet
myDataAdapter.Fill(myDataS et, "Employees")
Return myDataSet
End Function
End Class
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
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(cIte
Next
End Sub
Private Sub CboEmployee_SelectedIndexC
Dim cItem As cComboItem = CType(CboEmployee.Selected
MessageBox.Show(cItem.GetI
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=(loc
myDataAdapter = New SqlDataAdapter("SELECT * FROM employees", myConnection)
myDataSet = New DataSet
myDataAdapter.Fill(myDataS
Return myDataSet
End Function
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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.
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.
ASKER
thanks it works .......
ASKER
I will try this out and keep u posted within 2 days from now
Thx