473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Error message when binding a listbox

JR
I am attempting to display two list boxes. In the first list box is a listing of all entities. When a entity is selected and it has a subentity the second list box displays with a list of the subentities. The code works but I get an error at the following two steps: (Code is VB.Net on a form

'set the data source to the data set's table SubEntit
lstSubEntity.DataSource = dsData.Tables("SubEntity"

'display the columns subentity nam
lstSubEntity.DisplayMember = ("EntityName"

The error I receive is: Cast from type 'DataRowView' to type 'String' is not valid

Here is the entire code
Private Sub lstEntity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntity.SelectedIndexChange

'define a new data adapte
Dim daSubEntity As SqlClient.SqlDataAdapte

'using the new data adapter attempt to locate in the database table tblSubEntity a subentity for the selected entity
daSubEntity = New SqlClient.SqlDataAdapter("SELECT * FROM tblSubEntity WHERE Status = 1 AND CustomerID = " & lstEntity.SelectedValue & " ORDER BY EntityName", conn

'fill the data set's (dsData) table SubEntity with the data from the above select quer
daSubEntity.Fill(dsData, "SubEntity"

'set the data adapter to nothing, it is no longer needed after data set table has been fille
daSubEntity = Nothin

'determine if a subentity was found (no row in subentity). If no subentity was found then delete the table subentity and go to the function that will display the address based on the selected entity
If (dsData.Tables("SubEntity").Rows.Count < 1) The
'remove the subentity table since there are no records foun
dsData.Tables.Remove("SubEntity"
'hide the subentity selection screen (if visible
lblSubEntities.Visible = Fals
lstSubEntity.Visible = Fals
btnSortAlphaAscSE.Visible = Fals
btnSortAlphaDescSE.Visible = Fals
grpSubEntity.Visible = Fals
lblStep2.Visible = Fals
lblStep3.Visible = Fals
lblStep4.Visible = Fals
lblStep5.Visible = Fals
lblStep6.Visible = Fals
lblStep7.Visible = Fals
lblMailAddress.Visible = Fals
lblPhysicalAddress.Visible = Fals
lstAddress.Visible = Fals
cboDeptStrategy.Visible = Fals
cboDivisionStrategy.Visible = Fals
cboType.Visible = Fals
chkWolfYes.Visible = Fals
chkWolfNo.Visible = Fals
txtProjectDesc.Visible = Fals
txtProjectDesc.Text = "

'since there is no subentity show the addresses for the selected entity(go to function DisplayAddress, case Entit
DisplayAddress("Entity"
Exit Su
End I

'display the subentity selection scree
lblSubEntities.Visible = Tru
lstSubEntity.Visible = Tru
btnSortAlphaAscSE.Visible = Tru
btnSortAlphaDescSE.Visible = Tru
grpSubEntity.Visible = Tru

'set the data source to the data set's table SubEntit
lstSubEntity.DataSource = dsData.Tables("SubEntity") <== this is where I receive erro

'display the columns subentity nam
lstSubEntity.DisplayMember = ("EntityName") <== this is where I receive erro

'set the value member to the subentity id for later referenc
lstSubEntity.ValueMember = "SubEntityID

Catch eException As Exceptio
MsgBox("Error: " & eException.Message & " " & eException.Source
End Tr
End Su

Like I said, the code works even with the error messages. Any help in resolving this issue would be greatly appreciated.
Thanks, JR
Jul 21 '05 #1
2 1526
Wel
Try thi
1stSubEntity.DataSource=dsData.Tables["SubEntity"]
Maybe this will hel
L

----- JR wrote: ----

I am attempting to display two list boxes. In the first list box is a listing of all entities. When a entity is selected and it has a subentity the second list box displays with a list of the subentities. The code works but I get an error at the following two steps: (Code is VB.Net on a form

'set the data source to the data set's table SubEntit
lstSubEntity.DataSource = dsData.Tables("SubEntity"

'display the columns subentity nam
lstSubEntity.DisplayMember = ("EntityName"

The error I receive is: Cast from type 'DataRowView' to type 'String' is not valid

Here is the entire code
Private Sub lstEntity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntity.SelectedIndexChange

'define a new data adapte
Dim daSubEntity As SqlClient.SqlDataAdapte

'using the new data adapter attempt to locate in the database table tblSubEntity a subentity for the selected entity
daSubEntity = New SqlClient.SqlDataAdapter("SELECT * FROM tblSubEntity WHERE Status = 1 AND CustomerID = " & lstEntity.SelectedValue & " ORDER BY EntityName", conn

'fill the data set's (dsData) table SubEntity with the data from the above select quer
daSubEntity.Fill(dsData, "SubEntity"

'set the data adapter to nothing, it is no longer needed after data set table has been fille
daSubEntity = Nothin

'determine if a subentity was found (no row in subentity). If no subentity was found then delete the table subentity and go to the function that will display the address based on the selected entity
If (dsData.Tables("SubEntity").Rows.Count < 1) The
'remove the subentity table since there are no records foun
dsData.Tables.Remove("SubEntity"
'hide the subentity selection screen (if visible
lblSubEntities.Visible = Fals
lstSubEntity.Visible = Fals
btnSortAlphaAscSE.Visible = Fals
btnSortAlphaDescSE.Visible = Fals
grpSubEntity.Visible = Fals
lblStep2.Visible = Fals
lblStep3.Visible = Fals
lblStep4.Visible = Fals
lblStep5.Visible = Fals
lblStep6.Visible = Fals
lblStep7.Visible = Fals
lblMailAddress.Visible = Fals
lblPhysicalAddress.Visible = Fals
lstAddress.Visible = Fals
cboDeptStrategy.Visible = Fals
cboDivisionStrategy.Visible = Fals
cboType.Visible = Fals
chkWolfYes.Visible = Fals
chkWolfNo.Visible = Fals
txtProjectDesc.Visible = Fals
txtProjectDesc.Text = "

'since there is no subentity show the addresses for the selected entity(go to function DisplayAddress, case Entit
DisplayAddress("Entity"
Exit Su
End I

'display the subentity selection scree
lblSubEntities.Visible = Tru
lstSubEntity.Visible = Tru
btnSortAlphaAscSE.Visible = Tru
btnSortAlphaDescSE.Visible = Tru
grpSubEntity.Visible = Tru

'set the data source to the data set's table SubEntit
lstSubEntity.DataSource = dsData.Tables("SubEntity") <== this is where I receive erro

'display the columns subentity nam
lstSubEntity.DisplayMember = ("EntityName") <== this is where I receive erro

'set the value member to the subentity id for later reference
lstSubEntity.ValueMember = "SubEntityID"

Catch eException As Exception
MsgBox("Error: " & eException.Message & " " & eException.Source)
End Try
End Sub

Like I said, the code works even with the error messages. Any help in resolving this issue would be greatly appreciated.
Thanks, JR
Jul 21 '05 #2
Wel
Try thi
1stSubEntity.DataSource=dsData.Tables["SubEntity"]
Maybe this will hel
L

----- JR wrote: ----

I am attempting to display two list boxes. In the first list box is a listing of all entities. When a entity is selected and it has a subentity the second list box displays with a list of the subentities. The code works but I get an error at the following two steps: (Code is VB.Net on a form

'set the data source to the data set's table SubEntit
lstSubEntity.DataSource = dsData.Tables("SubEntity"

'display the columns subentity nam
lstSubEntity.DisplayMember = ("EntityName"

The error I receive is: Cast from type 'DataRowView' to type 'String' is not valid

Here is the entire code
Private Sub lstEntity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntity.SelectedIndexChange

'define a new data adapte
Dim daSubEntity As SqlClient.SqlDataAdapte

'using the new data adapter attempt to locate in the database table tblSubEntity a subentity for the selected entity
daSubEntity = New SqlClient.SqlDataAdapter("SELECT * FROM tblSubEntity WHERE Status = 1 AND CustomerID = " & lstEntity.SelectedValue & " ORDER BY EntityName", conn

'fill the data set's (dsData) table SubEntity with the data from the above select quer
daSubEntity.Fill(dsData, "SubEntity"

'set the data adapter to nothing, it is no longer needed after data set table has been fille
daSubEntity = Nothin

'determine if a subentity was found (no row in subentity). If no subentity was found then delete the table subentity and go to the function that will display the address based on the selected entity
If (dsData.Tables("SubEntity").Rows.Count < 1) The
'remove the subentity table since there are no records foun
dsData.Tables.Remove("SubEntity"
'hide the subentity selection screen (if visible
lblSubEntities.Visible = Fals
lstSubEntity.Visible = Fals
btnSortAlphaAscSE.Visible = Fals
btnSortAlphaDescSE.Visible = Fals
grpSubEntity.Visible = Fals
lblStep2.Visible = Fals
lblStep3.Visible = Fals
lblStep4.Visible = Fals
lblStep5.Visible = Fals
lblStep6.Visible = Fals
lblStep7.Visible = Fals
lblMailAddress.Visible = Fals
lblPhysicalAddress.Visible = Fals
lstAddress.Visible = Fals
cboDeptStrategy.Visible = Fals
cboDivisionStrategy.Visible = Fals
cboType.Visible = Fals
chkWolfYes.Visible = Fals
chkWolfNo.Visible = Fals
txtProjectDesc.Visible = Fals
txtProjectDesc.Text = "

'since there is no subentity show the addresses for the selected entity(go to function DisplayAddress, case Entit
DisplayAddress("Entity"
Exit Su
End I

'display the subentity selection scree
lblSubEntities.Visible = Tru
lstSubEntity.Visible = Tru
btnSortAlphaAscSE.Visible = Tru
btnSortAlphaDescSE.Visible = Tru
grpSubEntity.Visible = Tru

'set the data source to the data set's table SubEntit
lstSubEntity.DataSource = dsData.Tables("SubEntity") <== this is where I receive erro

'display the columns subentity nam
lstSubEntity.DisplayMember = ("EntityName") <== this is where I receive erro

'set the value member to the subentity id for later reference
lstSubEntity.ValueMember = "SubEntityID"

Catch eException As Exception
MsgBox("Error: " & eException.Message & " " & eException.Source)
End Try
End Sub

Like I said, the code works even with the error messages. Any help in resolving this issue would be greatly appreciated.
Thanks, JR
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
3
by: me | last post by:
I've included a picture below to show what I am trying to accomplish. It is best to copy/paste into notepad to get the spacing correct. I have a dataset that contains 3 tables. Two of the tables...
7
by: Max | last post by:
I'm using late binding to automate to Outlook and I'm getting an ArgumentException when I create a delegate. The arguments I pass seem valid. This is my code: Type oType =...
2
by: Allan Horwitz | last post by:
When I try to reference the lstproducts.selecteditem.value using autopostback from the lstproducts listbox I get an error? How can I fix my code to get the selected value from the lstproducts...
4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
5
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last...
1
by: JR | last post by:
I am attempting to display two list boxes. In the first list box is a listing of all entities. When a entity is selected and it has a subentity the second list box displays with a list of the...
1
by: pauled | last post by:
Hello all, Framework 1.1 VS 2003 Binding listbox. I have an array of objects that I am trying to use as the datasource for a listbox. The array is returned from a webservice and seems to be...
0
by: EricLondaits | last post by:
Hi, I have an ASP.NET page with a ListBox that is data bound to a table with a single field (it holds a list of valid IDs). The page also has a textBox into which you can add new valid IDs, one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.