读书人

下拉框数据有关问题

发布时间: 2012-02-23 22:01:34 作者: rapoo

下拉框数据问题
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConnection As New OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data.mdb ")

Dim mySelectQuery As String = "Update guanli set 密码= '77777 ' Where 用户名= '123 ' "



Dim mycommand As New OleDbCommand(mySelectQuery, myConnection)
myConnection.Open()
mycommand.ExecuteNonQuery()
myConnection.Close()

End Sub


这个是更新数据的代码,是可以通过的,现在我要把用户名123,换成下拉框里的某个选定值,该怎么改么 ?ComboBox1的什么属性?我用的用户名= ' "&ComboBox1.SelectedItem& " ' ,改成这样了不好用,该怎么改呢?

[解决办法]
绑定:
Me.ComboBox1.DataSource = getDs().Tables(0).DefaultView
Me.ComboBox1.DisplayMember = "id "
‘------------
更新:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New SqlConnection( "server=10.10.236.186;database=northwind;uid=sa;pwd=; ")
con.Open()
Dim rtn As Integer
Dim cmd As New SqlCommand
With cmd
.CommandText = "update test1 set name= '7777 ' where id= " & Me.ComboBox1.Text
.CommandType = CommandType.Text
.Connection = con
rtn = .ExecuteNonQuery()
End With
If rtn > 0 Then
MsgBox( "OK ")
Else
MsgBox( "Err ")
End If
End Sub

读书人网 >VB Dotnet

热点推荐