มันติดerrorมันบอกว่าsyntaxอะคับช่วยแก้ให้หน่อย
มันติดerrorมันบอกว่าsyntaxอะคับช่วยแก้ให้หน่อย Syntax error in INSERT INTO statement. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Source Error:
Line 38: Line 39: Cn.Open() Line 40: Cmd.ExecuteNonQuery()*****ตรงนี้มันขีดสีแดงอะคับ Line 41: Cn.Close() Line 42: End Sub
นี้คือโค๊ดมันนะคับพอดีผมจะเขียนบันทึกฐานข้อมูลคับ <%@ Page Language="VB" Debug="true" %> <%@ import Namespace="System.Data.OLEDB" %> <%@ import Namespace="System.Data" %> <script runat="server">
' Insert page code here Public Strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "data source= " & Server.MapPath("data\CE.mdb") Dim strsql As String
Dim ds As New DataSet Dim dt As DataTable Dim cn As New OleDbConnection(Strconn)
Sub Button1_Click(sender As Object, e As EventArgs) strsql = "insert into ma1(ID,name,position) values (@p1,@p2,@p3)"
Dim Cmd As New OleDbCommand(strsql, cn) Dim P1 As OleDbParameter
P1 = New OleDbParameter("@p1", OleDbType.VarChar, 10)
P1.Value = TextBox1.Text Cmd.Parameters.Add(P1)
P1 = New OleDbParameter("@p2", OleDbType.VarChar, 50)
P1.Value = TextBox2.Text Cmd.Parameters.Add(P1) P1 = New OleDbParameter("@p2", OleDbType.VarChar, 50)
P1.Value = TextBox3.Text Cmd.Parameters.Add(P1)
Cn.Open() Cmd.ExecuteNonQuery() Cn.Close() End Sub
|