Problems with binding a combobox

I got a form where you can enter information in textboxes and i got comboboxes where i want to choose some predefined options.

I binded the textboxes with the information in the database, and i am trying to bind the combobox with the database.

the problem is the combobox is showing information, but not all the options that it should be. It only shows the options that have been used in the call table. Also if you change the combobox to a value that is used in the second row of the table "calls", all the comboboxes changes to a value that is used in the second row, the same happens if you change 1 combobox back.

I think my problem is in the sql query

here is my connection string

Dim objConnectionAsNew SqlConnection("server=.\sqlexpress;uid=;pwd=;Trusted_Connection=yes;database=Helpdesk2")

Dim objDataAdapterAsNew SqlDataAdapter( _

"SELECT Call_ID, Date_Logged, Date_Closed, Problem_description, Action, Accepted_By, " & _

"Categorie_Description, Call_Status_Description, Priority_Description, FirstName " & _

"FROM Calls " & _

"JOIN Categorie ON Categorie.Categorie_ID = Calls.Categorie_ID " & _

"JOIN Call_status ON Call_status.Call_Status_ID = Calls.Call_Status_ID " & _

"JOIN Priority ON Priority.Priority_ID = Calls.Priority_ID " & _

"JOIN Employees ON Employees.EmployeeID = Calls.EmployeeID " & _

"ORDER BY Call_ID", objConnection)

Dim objDataSetAs DataSet

Dim objDataViewAs DataView

And this is what i use for the comboboxes

I commented ValueMember out because it errors on it with the following error

"Cannot bind to the new value member.
Parameter name: value"

cboCategorie.DropDownStyle = ComboBoxStyle.DropDownList

With cboCategorie

.DataSource = objDataSet.Tables(0)

.DisplayMember ="Categorie_Description"

'.ValueMember = "Categorie_ID"

'.SelectedIndex = 0

EndWith

cboPriority.DropDownStyle = ComboBoxStyle.DropDownList

With cboPriority

.DataSource = objDataSet.Tables(0)

.DisplayMember ="Priority_Description"

'.ValueMember = "Priority_ID"

'.SelectedIndex = "0"

EndWith

cboCallStatus.DropDownStyle = ComboBoxStyle.DropDownList

With cboCallStatus

.DataSource = objDataSet.Tables(0)

.DisplayMember ="Call_Status_Description"

'.ValueMember = "Categorie_ID"

'.SelectedIndex = 0

Also if i just use this part

"SELECT Catogorie_ID, Catogorie_Description, " & _

"FROM Catogorie " & _

"ORDER BY Catogorie_ID", objConnection)

and just bind the combobox on my form then it is just fine

so i can't get it to work with all the information in my sql query

If anyone could advise me on this

[5210 byte] By [Blaoo] at [2007-12-28]
# 1

HI Blaoo

Apologies if I have missed the point of the post, but hopefully this will help.

I suspect the databinding fails because you appear to be specifying a column name that does not exist in your datatable. ie, you need to add Categorie_ID and Priority_ID to your select statement.

With regards to missing data, once again this is probably the result of the SQL statement. It looks like you are using an INNER JOIN from the Calls to the Call_Status table. This means the only data from the Call_Status table that is returned, is that where the Calls_Status_ID.Status_ID exists in the Calls table.

To return all the Call_Status records, you would need to use a different join (depends on what db you are using) or refactor your sql a little. I always prefer to avoid unusual join types at it makes supporting things a little easier for the casual developer.

Try the following SQL statement and see if it solves your issues, noting that we start from the Categorie table and build on the data returned from that. The use of a LEFT JOIN to the Calls table, means all rows from Categorie will be returned.

Hope this helps. If you need any more assistance, please let me know

Richard

SELECT Call_ID, Date_Logged, Date_Closed, Problem_description, Action, Accepted_By, Categorie_Description, Call_Status_Description, Priority_Description, FirstName, Categorie.Categorie_ID, Priority.Priority_ID

FROM Categorie

LEFT JOIN Calls ON Categorie.Categorie_ID = Calls.Categorie_ID

INNER JOIN Call_status ON Call_status.Call_Status_ID = Calls.Call_Status_ID

INNER JOIN Priority ON Priority.Priority_ID = Calls.Priority_ID

INNER JOIN Employees ON Employees.EmployeeID = Calls.EmployeeID

ORDER BY Call_ID

DickDonny at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...