VB连接access数据库

前端之家收集整理的这篇文章主要介绍了VB连接access数据库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Imports System.Data.OleDb
Public Class InsertTest

    Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
        Dim oledb1 As New OleDbConnection
        oledb1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\liang.accdb"
        oledb1.Open()
        If ConnectionState.Open Then
            Dim cmd1 As New OleDbCommand
            cmd1.Connection = oledb1
            cmd1.CommandText = "Insert into 借书人(姓名,电话)values('" + TextBox1.Text + "'" + ",'" + TextBox2.Text + "')"
            cmd1.ExecuteNonQuery()
            oledb1.Close()
        End If
    End Sub
End Class

注意:以下黄色区两边的是双引号

"Insert into 借书人(姓名,电话)values('" + TextBox1.Text + "'" + ",'" + TextBox2.Text + "')"

猜你在找的VB相关文章