VB.NET SQL UPDATE命令返回错误“未为参数指定参数”。

时间:2011-07-12 04:23:28

标签: asp.net vb.net dataset ms-access-2007 sql-update

我的更新查询(从数据集向导构建)不会更新任何内容,我没有收到任何错误。

我检查了我的参数(param1)并且它正确传递。

当我调试我的即时窗口时,updateta.insertquery()告诉我:

  

没有为'Public Overridable Function UpdateQuery的参数'StockNum'指定参数(StockNum As String,Year As String,Make As String,Model as String,Color as String,Location As String,TiresNeeded As Boolean,StockIn As Date? ,SvcRONum As String,UCIStartDate As Date?,UCIEstCompleteDate As Date?,Repairs As Boolean,CollisionRONum As String,Detail As Date?,Other As String,OnLot As Boolean,OffProperty As Boolean,Sold as Boolean,Original_RecNum As Integer)As Integer ”。

为什么在某些日期之后会出现问号?

这是我的代码vb代码。有任何想法吗??谢谢!

    Protected Sub SubmitBTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateBTN.Click
        Dim updateta As New DataSet1TableAdapters.MasterTableAdapter
        updateta.UpdateQuery(StockNumTxt.Text, YearTxt.Text, MakeTxt.Text, ModelTxt.Text, ColorTxt.Text, LocationDropDownList.SelectedValue, TiresCHK.Checked, StockInDateTxt.Text, SrvcROnumTxt.Text, UCIStartDateTxt.Text, UCIEstComDateTXT.Text, RepairsCheckBX.Checked, CollisionRONumTXT.Text, DetailTXTbox.Text, OtherTxt.Text, OnLotCheckBX.Checked, OffPropertyCheckBX.Checked, SoldCheckBX.Checked, Request.QueryString("param1"))
        Response.Redirect("success.aspx")
    End Sub

    Function myCStr(ByVal test As Object) As String
        If isdbnull(test) Then
            Return ("")
        Else
            Return CStr(test)
        End If
    End Function

    Public Shared Function IsDBNull( _
 ByVal value As Object _
) As Boolean
        Return DBNull.Value.Equals(value)
    End Function

    Private Sub getData(ByVal user As String)
        'declare variables to fill
        Dim stock As String, make As String, color As String, stockin As Date, ucistart As Date, repairs As Boolean, _
            tires As Boolean, onlot As Boolean, sold As Boolean, year As Boolean, model As String, location As String, srvcRO As String, ucicompldate As Date, _
            collRO As String, other As String, offprop As Boolean, detail As Date

        Dim dt As New DataTable()
        Dim connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Jason\Desktop\UsedCarProductionSched\UsedCars.accdb;Persist Security Info=False;")
        connection.Open()
        Dim sqlcmd As String = "SELECT * from Master WHERE RecNum = @recnum"
        Dim FileCommand3 As New OleDb.OleDbCommand(sqlcmd, connection)
        FileCommand3.Parameters.AddWithValue("@recnum", user)
        Dim Reader3 As OleDb.OleDbDataReader = FileCommand3.ExecuteReader()
        If Reader3.Read Then

            stock = myCStr(Reader3("StockNum"))
            make = myCStr(Reader3("Make"))
            color = myCStr(Reader3("Color"))
            stockin = IIf(Reader3("stockin") Is DBNull.Value, Nothing, Reader3("stockin"))
            ucistart = IIf(Reader3("ucistartdate") Is DBNull.Value, Nothing, Reader3("ucistartdate"))
            repairs = Reader3("Repairs")
            tires = Reader3("tiresneeded")
            onlot = Reader3("onlot")
            sold = Reader3("sold")
            year = myCStr(Reader3("year"))
            model = myCStr(Reader3("model"))
            location = myCStr(Reader3("location"))
            srvcRO = myCStr(Reader3("svcROnum"))
            ucicompldate = IIf(Reader3("uciestcompletedate") Is DBNull.Value, Nothing, Reader3("uciestcompletedate"))
            collRO = myCStr(Reader3("collisionROnum"))
            other = myCStr(Reader3("other"))
            offprop = Reader3("offProperty")
            detail = IIf(Reader3("detail") Is DBNull.Value, Nothing, Reader3("detail"))

        End If
        connection.Close()

        If detail <> Nothing Then
            DetailTXTbox.Text = detail.ToString("M/dd/yyyy")
        Else : DetailTXTbox.Text = ""
        End If
        If ucicompldate <> Nothing Then
            UCIEstComDateTXT.Text = ucicompldate.ToString("MM/dd/yyyy")
        Else : UCIEstComDateTXT.Text = ""
        End If

        If stockin <> Nothing Then
            StockInDateTxt.Text = stockin.ToString("MM/dd/yyyy")
        Else : StockInDateTxt.Text = ""
        End If
        If ucistart <> Nothing Then
            UCIStartDateTxt.Text = ucistart.ToString("M/dd/yyyy")
        Else : UCIStartDateTxt.Text = ""
        End If
        StockNumTxt.Text = stock
        MakeTxt.Text = make
        ColorTxt.Text = color
        RepairsCheckBX.Checked = repairs
        TiresCHK.Checked = tires
        OnLotCheckBX.Checked = onlot
        SoldCheckBX.Checked = sold
        YearTxt.Text = year
        ModelTxt.Text = model
        If location <> Nothing Then
            LocationDropDownList.SelectedValue = location
        End If
        SrvcROnumTxt.Text = srvcRO
        CollisionRONumTXT.Text = collRO
        OtherTxt.Text = other
        OffPropertyCheckBX.Checked = offprop
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        getData(Request.QueryString("param1"))
    End Sub

2 个答案:

答案 0 :(得分:0)

对于Date?之后的问号,我很确定这表明Date是一个可以为空的字段。您的数据库表是否允许在这些字段上使用NULL?

当你在updateta.UpdateQuery之前放置一个调试断点时,你确定StockNumTxt.Text有一个值吗?

答案 1 :(得分:0)

#一样在日期周围进行访问。您是否尝试在日期值附近添加#个符号?