I am developing an application in vb.net and oracle as my database. my goal is to display the county names (display member) to the user while store county id (value member) in the combo box. when I run my code I get county id displayed in the combo box rather than the county names.
When I tried debugging my code I found out the display member and the value member get assigned the same value i.e ID.
What could possibly be wrong??
code
====================================
Dim Connect As OleDbConnection
Dim DA_County As OleDbDataAdapter
Dim DS_County As New DataSet()
Dim DT_County As New DataTable()
Dim gConnectString as string
Connect = New OleDbConnection(gConnectString)
Connect.Open()
DA_County = New OleDbDataAdapter("Select CountyName Name, CountyNo ID from ipt.tblcounty order by CountyName", Connect)
DA_County.Fill(DS_County)
DT_County = DS_County.Tables(0)
Originally posted by harshil_p
I am developing an application in vb.net and oracle as my database. my goal is to display the county names (display member) to the user while store county id (value member) in the combo box. when I run my code I get county id displayed in the combo box rather than the county names.
When I tried debugging my code I found out the display member and the value member get assigned the same value i.e ID.
What could possibly be wrong??
code
====================================
Dim Connect As OleDbConnection
Dim DA_County As OleDbDataAdapter
Dim DS_County As New DataSet()
Dim DT_County As New DataTable()
Dim gConnectString as string
Connect = New OleDbConnection(gConnectString)
Connect.Open()
DA_County = New OleDbDataAdapter("Select CountyName Name, CountyNo ID from ipt.tblcounty order by CountyName", Connect)
DA_County.Fill(DS_County)
DT_County = DS_County.Tables(0)
Let me know if this works. If not, we can try something else.
I tried using your code in my application, it errors out with the following message. It still shows up the county # in the combo box.
Thanks
Error Message:
===========================================
Could not bind to the new display member. Parameter name: newDisplayMember.
Originally posted by harshil_p
I tried using your code in my application, it errors out with the following message. It still shows up the county # in the combo box.
Thanks
Error Message:
===========================================
Could not bind to the new display member. Parameter name: newDisplayMember.
What is "errors out"?????
When I said errors out, I meant that the application produces an exception. The application does not crash since I used try and catch in my code to trap and display this error message.
The net result after running your code is that I still get the county names instead of county #.
I am really surprised why this is happening because my code which I had posted as a question works fine if I connect to a SQL Server database. It would somehow not work for Oracle. I dont know why??
I would like to correct my statement in my earlier response.
IT SHOULD HAVE BEEN:
The net result after running your code is that I still get the county # instead of county name.
Originally posted by harshil_p
When I said errors out, I meant that the application produces an exception. The application does not crash since I used try and catch in my code to trap and display this error message.
The net result after running your code is that I still get the county names instead of county #.
I am really surprised why this is happening because my code which I had posted as a question works fine if I connect to a SQL Server database. It would somehow not work for Oracle. I dont know why??
Ahh ha! Technically, the code is correct. What you're doing is fine, but it's one of those little annoyances that you must deal with. The annoyance here is the Oracle database. :o Ok... it should display the county names, but keep in mind that the ID is hidden. Do you want to show both the ID and name in the dropdown box? If so, you'll have to change your query. If this is what you want to do, I'll type it out.
Herb
Heck.. I'll just do it..
To show both of them in the dropdownlist box, just do this
DA_County = New OleDbDataAdapter("Select CountyNo, (CountyNo + ' ' + CountyName) as TheName From ipt.tblcounty order by CountyName", Connect)
DA_County.Fill(DS_County,"County")
I am having somewhat same problem with populating combo box. Though my combo box is showing correct data that I need but when I run the code I get this exception error message:
system.ArgumentException: Could not bind the new display member.
Parameter Name: newDisplayMeber.................
My Code:
Dim oraCntrDS As DataSet
oraCntrDS = New DataSet("CntrID")
oraCntrAdapter.Fill(oraCntrDS)