[VB.NET]DataGridView二次数据填充问题

前端之家收集整理的这篇文章主要介绍了[VB.NET]DataGridView二次数据填充问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
DataGridView二次数据填充问题 在Button1_Click后,现象是同一个表[SensorData]在DataGridView1中追加;DataGridView1.DataSource = Nothing没有起作用; 问题:Button1_Click多次后,怎样才能只显示一个不重复的表,谢谢 代码如下: Private Sub ReadDB() Dim constr As String = provider=microsoft.jet.oledb.4.0;data source= & Application.StartupPath & /EyeForSensor.mdb Dim sqlstr As String = Select * from SensorData order by Num asc Dim myconn As New OleDbConnection(constr) Dim mycomm As New OleDbCommand(sqlstr,myconn) myconn.Open() adapter = New OleDbDataAdapter(sqlstr,myconn) adapter.Fill(ds,SensorData ) DataGridView1.DataSource = ds.Tables( SensorData ) OLEB = New OleDbCommandBuilder(adapter) 获取或设置指定其名称包含空格或保留标记等字符的数据库对象(例如,表或列)时使用的开始字符 OLEB.QuotePrefix = [ OLEB.QuoteSuffix = ] End Sub Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click DataGridView1.DataSource = Nothing MsgBox( 重新装载test ) DataGridView1这里显示为空 ReadDB() 但是这里会把以前的填充都显示出来 End Sub __________________________________________________________________________ ds.Clear() 或者 ds = new dataset __________________________________________________________________________ 在 adapter.Fill(ds,SensorData ) 之前 __________________________________________________________________________ 万分感谢,搞定! 给分 __________________________________________________________________________

猜你在找的VB相关文章