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
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