Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient  'MySqlConnection的參考加入檔要記得加入

Public Class Form1

 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        '增新資料語法

        '連結 mySQL 資料庫
        Dim str As String = "Server=localhost;database=test;User Id=root;Password=root;pooling=false;"
        'Dim str As String = "Server=(local);database=資料庫名稱;User Id=帳戶名稱;Password=密碼;pooling=false;"
        'Dim str As String = "Server=伺服器名稱SQLexpress;database=資料庫名稱;User Id=帳戶名稱;Password=密碼;pooling=false;"
        Dim conn As MySqlConnection = New MySqlConnection(str)
        conn.Open()
        '查詢資料
        '  Dim str1 As String = "select * from product"
        Dim str1 As String = "Insert Into product (幹,您)Values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"  ' 注意前面不能是數字要不然會錯
        Dim adp1 As MySqlDataAdapter = New MySqlDataAdapter(str1, conn)
        '將查詢結果放到記憶體set1上的"1a "表格內
        Dim set1 As DataSet = New DataSet
        adp1.Fill(set1, "1a")
        '將記憶體的資料集合存放到視窗畫面上的DataGrid上
        DataGridView1.DataSource = set1.Tables("1a")
        '關閉資料庫的連結
        conn.Close()

       '顯示資料語法

        conn.Open()
        '查詢資料
        Dim str2 As String = "select * from product"
        Dim adp2 As MySqlDataAdapter = New MySqlDataAdapter(str2, conn)
        '將查詢結果放到記憶體set1上的"1a "表格內
        Dim set2 As DataSet = New DataSet
        adp2.Fill(set2, "1c")
        '將記憶體的資料集合存放到視窗畫面上的DataGrid上
        DataGridView1.DataSource = set2.Tables("1c")
        '關閉資料庫的連結
        conn.Close()


    End Sub

End Class



arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JL8051 的頭像
    JL8051

    不會的就放這邊

    JL8051 發表在 痞客邦 留言(0) 人氣()