none
ASP.net(VB) + ACCESS 插入数据时出错,SQL语句出错! RRS feed

  • 问题

  • Public Class ConnMDB
      Inherits System.Web.UI.Page
      Public Function ConnOpen(ByVal SQL As Object) As Object

        Dim myConnection As OleDbConnection
        Dim myCommand As OleDbCommand

        Dim dbname As String
        dbname = Server.MapPath("app_data/#blog.mdb")

        myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dbname)
        myConnection.Open()
        ' la1.text = "Connection Opened!"


        myCommand = New OleDbCommand(SQL, myConnection)

        myCommand.ExecuteNonQuery()
        myConnection.Close()

      End Function

    End Class

     

    以上是一个公共类。下面是一个普通ASPX页面。这个页面中需要插入数据。

     

      Protected Sub PLSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PLSave.Click
        Dim zzSave As String = zz.Text
        Dim ContentSave As Object = Content.Text
        Dim ViewID As Integer = Request.QueryString.Get("ID")
        Dim UserIP As String = Page.Request.UserHostAddress

        Dim PlSave As New ConnMDB

        ' Response.Write(zzSave & ContentSave & ViewID & UserIP) 经测试,全都有数据
        PlSave.ConnOpen("INSERT INTO [blogLY] ( [zz], [IP], [blog_ID],[content]) VALUES (  '" + zzSave + "','" + UserIP + "'," + ViewID + ",'" + ContentSave + "')")
      End Sub

     

    不知道为什么,一点南提交按钮,出错。出错如下:

     

    输入字符串的格式不正确。
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

    异常详细信息: System.FormatException: 输入字符串的格式不正确。

    源错误:

    行 23: 行 24: ' Response.Write(zzSave & ContentSave & ViewID & UserIP) 行 25: PlSave.ConnOpen("INSERT INTO [blogLY] ( [zz], [IP], [blog_ID],[content]) VALUES ( '" + zzSave + "','" + UserIP + "','" + ViewID + "','" + ContentSave + "')") 行 26: 行 27: 


     源文件: E:\自建网站\XuYongBo.com(.net)\View.aspx.vb 行: 25

    堆栈跟踪:

    [FormatException: 输入字符串的格式不正确。] Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +204 Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +89[InvalidCastException: 从字符串“INSERT INTO [blogLY] ( [zz], [IP”到类型“Double”的转换无效。] Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +225 Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value) +6 View.PLSave_Click(Object sender, EventArgs e) in E:\自建网站\XuYongBo.com(.net)\View.aspx.vb:25 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint


     

     

    十分奇怪。Content/IP/ZZ三个字段,都是string。而只有ViewID是数字类型。

    不解啊。

    2012年2月15日 10:59

答案