ComboBox1.DataSource = Nothing 清空后确实没有数据了,但是加载后之前的数据又重复显示出来了,如何搞的啊
ComboBox1.DataSource = Nothing 清空后确实没有数据了,但是加载后之前的数据又重复显示出来了,怎么搞的啊?
Private Sub ComboBox1_load()
Try
conn = New SqlConnection("server=(local);uid=sa;pwd=;database=uuu;Integrated Security=True")
conn.Open()
myCommand = New SqlCommand("Select * from User", conn)
sda.SelectCommand = myCommand
sda.Fill(ds, "User")
If ds.Tables(0).Rows.Count > 0 Then
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "username"
ComboBox1.ValueMember = "userid"
ComboBox1.Text = ""
'ComboBox1.SelectedValue = ""
Else
MsgBox("没记录")
End If
Catch
MsgBox(Err.Description)
End Try
conn.Close()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
'加载
ComboBox1_load()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'清空
ComboBox1.DataSource = Nothing
ComboBox1.Items.Clear()
End Sub
------解决方案--------------------
加载时 ComboBox1.DataSource = ds.Tables(0),这不是又指定了datasource吗
------解决方案--------------------
你的"清空"只是UI层面的并非真正的删除数据,没有操作数据库,所以下次进来的时候还会显示
------解决方案--------------------
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'清空
ds.Tables(0).rows.clear
End Sub
Private Sub ComboBox1_load()
Try
conn = New SqlConnection("server=(local);uid=sa;pwd=;database=uuu;Integrated Security=True")
conn.Open()
myCommand = New SqlCommand("Select * from User", conn)
sda.SelectCommand = myCommand
sda.Fill(ds, "User")
If ds.Tables(0).Rows.Count > 0 Then
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "username"
ComboBox1.ValueMember = "userid"
ComboBox1.Text = ""
'ComboBox1.SelectedValue = ""
Else
MsgBox("没记录")
End If
Catch
MsgBox(Err.Description)
End Try
conn.Close()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
'加载
ComboBox1_load()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'清空
ComboBox1.DataSource = Nothing
ComboBox1.Items.Clear()
End Sub
------解决方案--------------------
加载时 ComboBox1.DataSource = ds.Tables(0),这不是又指定了datasource吗
------解决方案--------------------
你的"清空"只是UI层面的并非真正的删除数据,没有操作数据库,所以下次进来的时候还会显示
------解决方案--------------------
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'清空
ds.Tables(0).rows.clear
End Sub