标题:INSERT INTO语句语法错误 求解
只看楼主
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
结帖率:86.96%
已结贴  问题点数:12 回复次数:4 
INSERT INTO语句语法错误 求解

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim logname As String
        Dim logpsw As String
        logname = TextBox1.Text
        logpsw = TextBox2.Text
        Dim connect As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
        connect.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/database/book.mdb"))
        Try
            connect.Open()
            Response.Write("SUCCEED")
        Catch ex As Exception
            Response.Write(ex)
        End Try
        Try
            Dim cmd As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand
            Dim result As Integer
            cmd.Connection = connect
             =
             = "insert into BOOK (username,password) values ('" + logname + " ',' " + logpsw + " ')"
            result = cmd.ExecuteNonQuery()
            Response.Write("write successfully")
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
        connect.Close()

    End Sub

点了这个button以后,打开数据库成功,显示SUCCEED,但紧接着就报错说INSERT INTO 语句的语法错误,补充一下,相应的ACCESS数据库里的BOOK表里所有属性都可以是空值。。。。。希望大虾们赐教


再补充一下response.write()后的运行结果是
insert into BOOK (username,password) values ('ASS ',' ASS ')
应该没问题

[ 本帖最后由 kiska3088915 于 2010-11-4 14:48 编辑 ]
搜索更多相关主题的帖子: INSERT INTO 语法 语句 求解 
2010-11-04 14:39
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
得分:4 
我怎么看着不像ASP的代码啊。

----我怎能在别人的苦难面前转过脸去----
2010-11-04 15:05
jingjing316
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:293
专家分:541
注 册:2009-8-11
得分:4 
好像没有什么错误,把连接符换一下试试
"insert into BOOK (username,password) values ('" & logname &" ','" & logpsw & " ')"
2010-11-04 17:19
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:0 
我知道了,是PASSWORD这个和关键字冲突了,加个中括号就解决了
2010-11-05 22:01
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:0 
回复 2楼 dzt0001
VS2008上用VB写的
2010-11-05 22:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-324961-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.085765 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved