无法找到用新的数据替换以前数据的方法....
我使用按钮在dgv中查看我的表格。当我单击按钮两次查看我的表时,它只显示下一个数据
这是我正在使用的代码
Private Sub cmdview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdview.Click
connetionstring = "Integrated Security = SSPI; data source= DELL-PC;Initial catalog=Library System"
connection = New SqlConnection(connetionstring)
sql = "select * from dbo.tblbook"
Try
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
connection.Close()
dtg1.DataSource = ds.Tables(0)
Return
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
答案 0 :(得分:0)
http://msdn.microsoft.com/en-us/library/bh8kx08z.aspx “只有当表和列不存在时才会创建它们;否则Fill将使用现有的DataSet模式。” 如果您在数据集中有数据,则表示如果使用填充,则不会覆盖该数据。所以在你的适配器之前尝试这个。填充行:
ds.Clear()