10/10/2018, 10:05
Đúng theo sách ASP nhưng sao lại báo lỗi??? help me!!!
Mình cũng bị dzính chưởng như bạn ý, nhưng là dzính chưởng với lệnh UPDATE, nó báo sai cấu trúc hoài mặc dù những table trước mình đều Update và Inser ngon lành, cuối cùng thì đã phát kiến ra lỗi sai ko thể ngờ tới, đó là cái tội đạt tên các cột là UserName và Password, hix hix, thế là ông nội IIS báo lỗi miết. Giờ đổi lại là User & Pass thì OK rồi, thanks nhiều nha
Bài liên quan
<%@codepage="65001"%>
<%
dim strConn
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "& server.mappath("Love2u.mdb")
UserName="thanhcong"
Password="111"
set Conn=Server.CreateObject("ADODB.Connection")
Conn.Open strConn
sql="Insert into ADMIN(USERNAME,PASSWORD) values("
sql=sql & "'"&UserName&"','"&Password&"')"
Response.write(sql)
Conn.Execute sql
Conn.Close
set Conn=nothing
%>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test insert data</title>
</head>
<body>
</body>
</html>
------------------------------------------------------------------
Còn đây là trang báo lỗi:
HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services
--------------------------------------------------------------------------------
Technical Information (for support personnel)
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
/Test/testadd.asp, line 12
Mình đã thử nhiều cách khác như đổi chuỗi kết nối, đổi câu lệnh SQL insert trực tiếp chứ ko dùng qua biến nhưng cũng bị báo lỗi (Conn.Execute sql). Không hiểu nỗi!!! Nhờ các bạn chỉ ra chỗ sai của mình nha. Thanks.
(Vì bạn đang dùng ADO nên cú pháp cần viết thế này)
2. Bạn thay cú pháp SQL thành
sql="Insert into ADMIN(USERNAME,PASSWORD) SELECT '" & UserName & "' AS Expr1, '" & Password & "' AS Expr2;"
Dim conn, strConn, dbPath
dbPath = Server.MapPath(".")&"\GB.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
strConn= "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & dbPath
conn.Open strConn
Sau đó, kiểm tra lại xem chữ in thường và in hoa tên của Table và các fields thế nào .
chúc thành công
sql="Insert into bang_admin(matruycap,matkhau)values('"&UserName&"' ,'"&Password&"')"
đổi tên bảng admin luôn đi,đổi nó thành bang_admin(matruycap,matkhau).rồi insert vào
sql="Insert into bang_admin(matruycap,matkhau)values('"&UserName&"' ,'"&Password&"')".không được nữa thì thua luôn á