开发者

Refreshing a DataGridView binded with a access database

I have created in Visual Basic .net a new DataGridView in my form. I have used the wizard to show some fields of a table in my access database. I would like to add a refresh button and for开发者_开发知识库ce the datagrid to load the data again from the database, but I'm not sure how to do that. I have tried several refresh method but it does not work. Can anybody help me?


You need to bind the datasource again. I've never done this with an Access database but here's how you might do it using ADO.NET with SQL

Using command As New SqlCommand("CommandText Goes Here", "ConnectionString goes here")
    command.CommandType = CommandType.Text
    Dim ds As New DataSet("Results")
    Using da As New SqlDataAdapter(command)
        da.Fill(ds)
        myGrid.DataSource = ds
    End Using
End Using

So you could wrap that up in a button click event.

There are a ton of other ways of doing this but that works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜