C#
|
|
 |

|
Hi,
I am using below codes to bind data to a list box. But I got this error.
DataTable tbl= new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter("select * from myTable", mycon);
if (da == null)
return;
da.Fill(tbl);
myListBox.DataSource = tbl.DefaultView ; // Throw error
myListBox.DisplayMember = "CustomerName"; // Throw error
myListBox.ValueMember = "CustomerCode"; // Throw error
Are there anyone can help ?
Thanks and regards,
|
|
|
|

|
You forgot to include the error-message in your post. I assume you did set a connectionstring and the likes?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|

|
The error-message is same as the topic: No value given for one or more required parameters
Kind regards,
|
|
|
|

|
Ah. Can you post it, including the stack-trace?
Try setting the datasource after setting the displaysource and valuemember.
Can you also show us the code where the connection is created?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|

|
Thanks Eddy,
I tried to set the datasouce after setting the displaysource and valuememember. Then, I only got the error at the line setting datasource.
This is the connection string: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=./data/system.mdb.
And after the line: da.Fill(tbl);
the DataTable variable tbl still has data
|
|
|
|

|
CustomerName and CustomerCode are columns should be valid columns in the myTable table.
|
|
|
|

|
Hi all,
I resolved this problem.
After the statement:
myListBox.DataSource = tbl.DefaultView ;
It call to the event "Selected Index Change" of the listbox. In this event, I used a statement:
string code = myListBox.SelectedValue.ToString(); But myListBox.SelectedValue.ToString() return type DataRowView (not code value, because the datatable includes two columns), and it created the error.
So, I moved the setting DataSource after setting DisplayMember and ValueMember then it is ok
|
|
|
|

|
Cool. Thanks for posting the solution here.
|
|
|
|

|
In a C# 2008 desktop application, I am finding that there are processes that are not released once when the application finishes executing.
Every time this application runs, there are more processes that are not released. I want to mention this application was originally written as a console application, but was changed to a windows application since I did not want all the dos popup windows.
I do want to mention that in this application the following is not occuring:
1. When some of the objects are created, there is no dispose on the objects.
2. Some of the linq statements do not have a using clause on them.
What kind of code could be causing this problem?
Thus can you tell me, point me to a reference, and/or show me code on how to reolve this problem?
modified 15 Feb '13 - 15:42.
|
|
|
|

|
classy_dog wrote: What kind of code could be causing this problem?
A "foreground" thread that should have been a background thread; the app would be running on the background until the thread dies, whereas a backgroundthread is terminated when the app closes.
That's assuming that you're launching these processes; otherwise they wouldn't be related to your code.
(Just to check, with a process, you did mean a "running executable"?)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
 |
|
|
General
News
Suggestion
Question
Bug
Answer
Joke
Rant
Admin