如何在预加载数据时访问datagridview组件?

时间:2018-02-18 02:02:39

标签: vb.net datagridview

我希望能够访问该表,以便我可以添加DataGridView.AutoSizeColumnsMode来填充,并且还可以访问表的其余部分,以便我可以编写添加,编辑和删除访问数据库的按钮的代码

我只是不知道怎么做,因为我不熟悉数据库,加载它们并保存它们

'Declarations
Dim con As New SqlClient.SqlConnection
Dim ds As New DataSet
Dim sqlString As String = "SELECT * FROM Items"
Dim da As New SqlClient.SqlDataAdapter(sqlString, con)

'Opening Load
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con.ConnectionString = "Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True"
    con.Open()

    da.Fill(ds, "ItemsTable")

    DataGridView1.DataSource = ds.Tables("ItemsTable")
End Sub

0 个答案:

没有答案