| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1387 人关注过本帖
标题:asp.net中VB的语法有错
取消只看楼主 加入收藏
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
结帖率:100%
收藏
 问题点数:0 回复次数:6 
asp.net中VB的语法有错
Dim sd As New Data.OleDb.OleDbCommand("insert into user(user,pwd)values ('+use_txt.Text+','+pwd_txt.Text+')", dd)
总报sql语句有错,请问一下如何改呀
搜索更多相关主题的帖子: 语法 asp pwd txt Text 
2008-05-16 10:31
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
我加了'"&&"'也不对

网络改变了我,编程改变了我的生活
2008-05-16 10:53
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
还是一样报错
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dd As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\md.mdb"))
        Dim sd As New Data.OleDb.OleDbCommand("insert into user(user,pwd)  values (' + use_txt.Text+  ','+ pwd_txt.Text + ')", dd)
        Try
            dd.Open()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
        Try
            sd.ExecuteNonQuery()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try

        Response.Write("<script language='jvavscript'>alert('操作成功');</script>")
    End Sub
End Class

网络改变了我,编程改变了我的生活
2008-05-16 11:48
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
是呀,我问的都有点不好意思了,真不明白为什么try得到的错误就是SQL语法错误

网络改变了我,编程改变了我的生活
2008-05-16 13:47
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
输入那句话还是可以正常,就是运行时报错
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Write(use_txt.Text)
        Response.Write("<br>")
        Response.Write(pwd_txt.Text)
        Response.Write("<br>")
        Dim dd As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\md.mdb"))
        Dim sql As String = "insert into user(user,pwd)  values ( '" + use_txt.Text + "' ,'" + pwd_txt.Text + " ')"
        Response.Write(sql)
        Response.Write("<br>")
        dd.Open()
        Dim sd As New Data.OleDb.OleDbCommand(sql, dd)


        Try
            sd.ExecuteNonQuery()
        Catch ex As Exception
            Response.Write(ex.ToString)
        End Try




        Response.Write("<script language='jvavscript'>alert('操作成功');</script>")
    End Sub
End Class


运行结果:
asdsa
sadsa
insert into user(user,pwd) values ( 'asdsa' ,'sadsa ')
System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) 在 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() 在 _Default.Button1_Click(Object sender, EventArgs e) 位置 F:\\Default.aspx.vb:行号 19

网络改变了我,编程改变了我的生活
2008-05-16 14:30
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
把它移到别的盘就可以正常运行了,怪怪的

网络改变了我,编程改变了我的生活
2008-05-17 09:24
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
这个是可以正常运行,放到那个分区也不可以运行了,这种事如何解释。
Partial Class show
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
        'Response.Write(i)
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn = New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Server.MapPath("mdb.mdb"))
        Dim sql As String = "select * from dcontd"
        Dim comm = New Data.OleDb.OleDbCommand(sql, conn)
        conn.open()
        Dim ds As Data.OleDb.OleDbDataReader
        ds = comm.ExecuteReader()

        While (ds.Read())
            Response.Write(Convert.ToSingle(ds("id")))
            Response.Write("<br>")
            Response.Write(Convert.ToString(ds("dotype")))
            Response.Write("<br>")
            Response.Write(Convert.ToString(ds("dtext")))
            Response.Write("<br>" & "新记录:")
            Response.Write(Convert.ToString(ds("daddress")))
            Response.Write("<br>")
        End While
        ds.Close()
        conn.close()

        Dim sqll As String = "insert into dcontd(daddress,dtext)values('" + user.Text + "','" + pwd.Text + "')"
        Dim con = New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Server.MapPath("mdb.mdb"))
        con.open()
        Dim cc = New Data.OleDb.OleDbCommand(sqll, con)
        cc.executenonquery()



    End Sub
End Class

网络改变了我,编程改变了我的生活
2008-05-17 09:30
快速回复:asp.net中VB的语法有错
数据加载中...
 
   



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

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