|
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 ;
myListBox.DisplayMember = "CustomerName";
myListBox.ValueMember = "CustomerCode";
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.
|
|
|
|