怎样更新DataGridView里面的数据呢?
我的程序是这样写的
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter()
Dim myDataSet As DataSet = New DataSet
Dim strSQL = "SELECT * from mediafile "
Try
conn.Open()
myDataAdapter.SelectCommand = New SqlCommand(strSQL, conn)
myDataAdapter.Fill(myDataSet)
Me.DataGridView2.DataSource = myDataSet.Tables( "mediafile ")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
conn.Close()
End Sub
没有报告错误
DataGridView里面的数据被清除,什么都没有
这是怎么回事?
[解决办法]
Me.DataGridView2.DataSource = myDataSet.Tables( "mediafile ")
这一句改为
Me.DataGridView2.DataSource = myDataSet.Tables(0)
试试.