 |
|
ตรวจสอบให้หน่อยครับ จนใจจริงๆ มันบอกว่าผิดที่ Insert to Option Explicit On Option Strict On Imports System.Data Imports System.Data.OleDb |
|
 |
|
|
 |
 |
|
มันบอกว่าผิดที่ Insert to
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub ButtonR_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonR.Click
Dim strConn As String
strConn = "Provider=Microsoft.JET.OLEDB.4.0;data source=" & Server.MapPath("~/App_Data/userdatabase.mdb")
Dim Conn As New OleDbConnection(strConn)
Conn.Open()
Dim sqluser As String
sqluser = "INSERT INTO User (UserName,Password,Name,Lastname,Sex,Location,comment)"
sqluser &= " Values ('" & Txtuser.Text & "',"
sqluser &= "'" & Txtpass.Text & "',"
sqluser &= "'" & Txtname.Text & "',"
sqluser &= "'" & Txtlname.Text & "',"
sqluser &= "'" & Txtsex.Text & "',"
sqluser &= "'" & Txtloca.Text & "',"
sqluser &= "'" & Txtcom.Text & "')"
Dim Com As New OleDbCommand(sqluser, Conn)
Com.ExecuteNonQuery()
Response.Redirect("Default.aspx")
Conn.Close()
End Sub
End Class
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
15 ต.ค. 2550 00:14:27 |
By :
electiss |
View :
1548 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
sqluser &= น่าจะเป็น sqluser .=
|
 |
 |
 |
 |
Date :
15 ต.ค. 2550 10:14:54 |
By :
iNY |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Dim StringSql As String = String.Format("insert into tb(id,name) values ('{0}','{1}')",Me.TxtID.Text.Trim(),Me.TxtName.Text.Trim()) อ่ายง่ายก่าน้า
ส่วน &= ก็ถูกนะ คง ' หรือ "" เกิน
|
 |
 |
 |
 |
Date :
20 ต.ค. 2550 00:20:20 |
By :
bomครหวัน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้เป็น
Dim sqluser As String
sqluser = "INSERT INTO User (UserName,Password,Name,Lastname,Sex,Location,comment)"& _
'" VALUES ('" & Trim(txtUser.text) & "','" & Trim(txtPass.Text) & "','" & Trim(txtName.Text) & "','" & Trim(txtlname.Text) & "','" & Trim(txtsex.Text) & "','" & Trim(txtloca.Text) & "','" & Trim(txtcom.Text) & "')
myconn.Open()
myCommand = New OleDbCommand(SQLGar, myconn)
myCommand.ExecuteNonQuery()
myconn.Close()
Response.Redirect("Default.aspx")
end sub
ลองดูนะคะ เพราะโบว์ใช้การ Insert into แบบนี้แล้วไม่เคยมีปัญหาเลยค่ะ นอกจากว่าเครื่องหมายจะผิด หรือเกิน ต้องระวังด้วยนะคะ
ขอให้โชคดีค่ะ
|
 |
 |
 |
 |
Date :
7 พ.ย. 2550 09:50:25 |
By :
โบว์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|