簡體   English   中英

MS Accss2010中條件表達式中的數據類型不匹配

[英]Data type Mismatch in criteria expression in MS Accss2010

我嘗試執行INSERT查詢,但拋出上述錯誤。 我在下面給出了我的代碼。

public string InsertMoveDetails(string desc, string currentLocation, string newLocation, string newBay, string requestedBy, string movedBy, string approvedBy, DateTime dateOfMove)
{

        string desc, currentLocation, newLocation, movedBy, approvedBy, requestedBy,newBay;
        DateTime dateOfMove;

        desc = textBoxDescription.Text;
        currentLocation = textBoxCurrentLocation.Text;
        newLocation = comboBoxNewLocation.Text;
        movedBy = comboBoxMovedBy.Text;
        approvedBy = comboBoxApprovedBy.Text;
        dateOfMove = dateTimePickerDateOfMove.Value;           
        newBay = textBoxNewBay.Text;
        requestedBy = textBoxRequestedBy.Text;

        con.Open();
        OleDbCommand cmd1 = new OleDbCommand("INSERT INTO MoveDetails(Descrptn, CurrentLocation, NewLocation, NewBay, RequestedBy, MovedBy, ApprovedBy, DateOfMove) VALUES(@Descrptn, @CurrentLocation, @NewLocation, @NewBay, @RequestedBy, @MovedBy, @ApprovedBy, @DateOfMove)", con);

        cmd1.Parameters.AddWithValue("@Descrptn", desc);
        cmd1.Parameters.AddWithValue("@CurrentLocation", currentLocation);
        cmd1.Parameters.AddWithValue("@NewLocation", newLocation);
        cmd1.Parameters.AddWithValue("@NewBay", newBay);
        cmd1.Parameters.AddWithValue("@RequestedBy", requestedBy);
        cmd1.Parameters.AddWithValue("@MovedBy", movedBy);
        cmd1.Parameters.AddWithValue("@ApprovedBy", approvedBy);
        cmd1.Parameters.AddWithValue("@DateOfMove", dateOfMove);

        cmd1.ExecuteNonQuery();
        con.Close();
        return "";
    }

我的數據庫列及其各自的類型是

描述-文字
當前位置-文字
NewLocation-文字
紐貝-文字
文字要求
MovedBy-文字
批准文字
DateOfMove-日期/時間

請幫我解決這個錯誤。 我嘗試了其他具有相同錯誤的線程,但找不到答案。

嘗試從所有參數中刪除@,並在SQL中將所有參數替換為?,我不認為Access支持命名參數。

我嘗試使用此代碼。

dateOfMove = Convert.ToDateTime(dateTimePickerDateOfMove.Text);

那對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM