ช่วยดูให้หน่อยครับพอผม run มันก็ Error ตรง ExecuteNonQuery ทุกที่เลยครับ
อบากทราบว่าต้องทำยังไงครับ ถ้ามีคำอธิบายว่าทำไมมันถึงเกิดก็ขอบคุณมากครับ
Code (VB.NET)
Imports System.Data.OleDb
Imports System.Data
Public Class Form4
Public conn As New OleDbConnection
Public Sub connectData() Handles MyBase.Load
Dim S As String
If conn.State = ConnectionState.Open Then conn.Close()
S = "Provider = Microsoft.ACE.OLEDB.12.0;"
S = S + "Data Source=C:\Data\Data.accdb;"
S += "User Id=admin;Password=;"
conn.ConnectionString = S
conn.Open()
End Sub
Private Sub formload() Handles MyBase.Load
connectData()
End Sub
Public Function ExecuteSQL(ByVal prmSQL As String) As Boolean
connectData()
Dim addCom As New OleDbCommand
With addCom
.CommandType = CommandType.Text
.CommandText = prmSQL
.Connection = conn
.ExecuteNonQuery()
End With
ExecuteSQL = True
End Function
Private Sub AddData() Handles Button1.Click
ExecuteSQL("INSERT INTO Data(Number,network,money) VALUES ('" & TextBox1.Text & "')")
Dim Sql As String
Sql = "INSERT INTO Data(Number)("
Sql += "'" & TextBox1.Text & "',"
Sql += ")"
MessageBox.Show("เบอร์โทรของคุณคือ " & Sql & " ค่ะ", "เบอร์โทรของคุณคือ", MessageBoxButtons.OK)
End Sub
End Class
Imports System.Data.OleDb
Imports System.Data
Public Class Form4
Public conn As New OleDbConnection
Public Sub connectData() Handles MyBase.Load
Dim S As String
If conn.State = ConnectionState.Open Then conn.Close()
S = "Provider = Microsoft.ACE.OLEDB.12.0;"
S = S + "Data Source=C:\Data\Data.accdb;"
S += "User Id=admin;Password=;"
conn.ConnectionString = S
conn.Open()
End Sub
Private Sub formload() Handles MyBase.Load
connectData()
End Sub
Public Function ExecuteSQL(ByVal prmSQL As String) As Boolean
connectData()
Dim addCom As New OleDbCommand
With addCom
.CommandType = CommandType.Text
.CommandText = prmSQL
.Connection = conn
.ExecuteNonQuery()
End With
ExecuteSQL = True
End Function
Private Sub AddData() Handles Button1.Click
ExecuteSQL("INSERT INTO Data(Number,network,money) VALUES ('" & TextBox1.Text & "')")
Dim Sql As String
Sql = "INSERT INTO Data(Number)("
Sql += "'" & TextBox1.Text & "',"
Sql += ")"
MessageBox.Show("เบอร์โทรของคุณคือ " & Sql & " ค่ะ", "เบอร์โทรของคุณคือ", MessageBoxButtons.OK)
End Sub
End Class