在vb.net中为网站显示gridview中的表格

时间:2014-10-15 16:51:20

标签: asp.net .net ms-access

我是vb.net的新手,我想在ASP.NET secnario中使用vb.net在gridview中显示Access表。

Public Class Form1
    Public Sub New()
        InitializeComponent()
        BindGrid()
    End Sub

    Private Sub BindGrid()
        Dim constring As String = "Data Source=.\SQL2005;Initial Catalog=Northwind;User id = sa;password=pass@123"
        Using con As New SqlConnection(constring)
            Using cmd As New SqlCommand("SELECT * FROM Customers", con)
                cmd.CommandType = CommandType.Text
                Using sda As New SqlDataAdapter(cmd)
                    Using dt As New DataTable()
                        sda.Fill(dt)
                        GridView1.DataSource = dt
                    End Using
                End Using
            End Using
        End Using
    End Sub
End Class

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

要使用ACCESS数据库,您必须更改连接字符串。

Dim constring As String = "Data Source=.\SQL2005;Initial Catalog=Northwind;User id = sa;password=pass@123"

    http://www.connectionstrings.com/access/

另外

                Using ds As New DataSet()
                    sda.Fill(ds)
                    GridView1.DataSource = ds.Table(0)
                    GridView1.DataBind()
                End Using