none
มันเพิ่มข้อมูลไม่ได้มันผิดตรงใหน่หรือป่าวคับ#กำลังหัดทำคับ RRS feed

  • คำถาม

  • Imports System.Data
    Imports System.Data.OleDb
    Public Class Form1
        Public con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\FanFilm\Desktop\Product.accdb")
        Public cmd As OleDbCommand
        Public da As OleDbDataAdapter
        Public strsql As String


        Sub gridview()
            strsql = "select * from Product"
            da = New OleDbDataAdapter(strsql, con)
            Dim dt As New DataTable
            da.Fill(dt)
            DataGridView1.DataSource = dt
        End Sub

        Sub conn()
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            con.Open()
        End Sub

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            gridview()
            conn()
        End Sub

        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            GroupBox1.Enabled = True
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            cmd = New OleDbCommand("insert into product(ID,name,num) valuse ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')", con)
            conn()
            cmd.ExecuteNonQuery()
            MessageBox.Show("บันทึกเรียบร้อย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information)
            strsql = "select * from Product"
            da = New OleDbDataAdapter(strsql, con)
            Dim dt As New DataTable
            da.Fill(dt)
            DataGridView1.DataSource = dt
        End Sub

    End Class
    2 กุมภาพันธ์ 2562 9:04

ตอบทั้งหมด

  • สวัสดีค่ะ
    เมื่อทำการดีบั๊ก สามารถแก้ไขตามข้อผิดพลาดที่ปรากฏ

    โปรดดูตัวอย่างต่อไปนี้

    ขอบคุณค่ะ


    MSDN Community Support Please remember to click Mark as Answer ,the responses that resolved your issue, and to click Unmark as Answer if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • แก้ไขโดย Julia TuoModerator 4 กุมภาพันธ์ 2562 3:34
    • เสนอเป็นคำตอบโดย Julia TuoModerator 8 กุมภาพันธ์ 2562 2:02
    4 กุมภาพันธ์ 2562 3:32
    ผู้ดูแล