Combobox doesnot update valuemember??

A

al

Greetings,

As I understands it, SelectedValud of combobox reads its value from
ValueMember property of the combobox. This doesn't work with me. What
happens is just randome update. This is the code,


'Here I set connectin and commands

Dim cn As SqlConnection = New SqlConnection(str)
Dim cmd As SqlCommand = New SqlCommand("SELECT E1.EmployeeID,
E1.Title," & _
"E2.FirstName + ' ' + E2.LastName AS ReportsTo,E1.FirstName," &
_
"E1.LastName FROM Northwind..Employees AS E1 LEFT OUTER JOIN" &
_
" Northwind..Employees AS E2 ON E2.EmployeeID = E1.ReportsTo",
cn)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(cmd)


'This fills dataset and initializes combobox values

da.Fill(ds, "employees")
cboreportsto.DataSource = ds.Tables("employees")
cboreportsto.DisplayMember = "ReportsTo"
cboreportsto.ValueMember = "EmployeeID"
txtid.DataBindings.Add("text", ds, "employees.employeeid")
txtfirstname.DataBindings.Add("text", ds,
"employees.firstname")
txtlastname.DataBindings.Add("text", ds,
"employees.lastname")
cboreportsto.DataBindings.Add("text", ds,
"employees.ReportsTo")

'Here I do update to database, but no update real happens, just
randome one

cmd = cn.CreateCommand
cmd.CommandText = "updateemployees"
cmd.CommandType = CommandType.StoredProcedure
AddHandler cboreportsto.TextChanged, AddressOf cbochanged
With cmd.Parameters
.Add(New SqlParameter("@employeeid", SqlDbType.NVarChar, 50)).Value =
txtid.Text
.Add(New SqlParameter("@lastname", SqlDbType.NVarChar,
10)).Value = txtlastname.Text
.Add(New SqlParameter("@firstname", SqlDbType.NVarChar,
10)).Value = txtfirstname.Text
.Add(New SqlParameter("@Reportsto", SqlDbType.Int, 40)).Value =
cboreportsto.SelectedValue

End With
Try
cmd.ExecuteNonQuery()


MTIA,
Grawsha
 
W

William Ryan

You're binding to the Text Property, try SelectedValue. I can't remember if
it's SelectedValue or SelectedIndex, but I'm 99% sure it's the first one.

HTH,

Bill
 
B

Bo Diddly

Yes, it is SelectedValue.

I just went through this with my program!

Good luck,

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top