【问题标题】:System.Data.OleDb.OleDbException: 'Data type mismatch in criteria expression.' Grid view updateSystem.Data.OleDb.OleDbException:“标准表达式中的数据类型不匹配。”网格视图更新
【发布时间】:2020-07-13 10:13:47
【问题描述】:

我正在更新网格视图,但 System.Data.OleDb.OleDbException: '标准表达式中的数据类型不匹配错误。请有人帮忙。 protected void ResultGridView_RowUpdating(对象发送者,GridViewUpdateEventArgs e) {

    TextBox txtFName2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtFName");
    TextBox txtDate2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtSM");
    TextBox txtCaseType2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCaseType");
    TextBox txtFileno2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtFileno");
    TextBox txtCustName2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCustName");
    TextBox txtAddress2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCustName");
    TextBox txtConno2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtConno");
    TextBox txtPlotarea2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtPlotarea");
    TextBox txtPlotRate2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtPlotRate");
    TextBox txtconstarea2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtconstarea");
    TextBox txtConstFloor2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtConstFloor");
    TextBox txtconstrate2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtconstrate");
    TextBox txtPlotvalue2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtPlotvalue");
    TextBox txtconstvalue2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtconstvalue");
    TextBox txttotalvalue2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txttotalvalue");
    TextBox txtRemarks2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtRemarks");

    **TextBox txtDatee2 = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtDate2");**

    string da = txtDatee2.Text.ToString();

    DateTime dt =
 DateTime.ParseExact(da, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
    string dateshort = dt.ToShortDateString();

    string ID = ResultGridView.DataKeys[e.RowIndex].Values[0].ToString();

    cmd.Connection = conn;
    cmd.CommandText = "UPDATE Final SET Finance ='" + txtFName2.Text + "' ,SM ='" + txtDate2.Text + "',Case_Type ='" + txtCaseType2.Text + "',File_no ='" + txtFileno2.Text + "',Cust_Name ='" + txtCustName2.Text + "' ,Address ='" + txtAddress2.Text + "',Con_no ='" + txtConno2.Text + "' ,Plot_area ='" + txtPlotarea2.Text + "' ,Plot_Rate ='" + txtPlotRate2.Text + "' ,const_area ='" + txtconstarea2.Text + "' ,Const_Floor ='" + txtConstFloor2.Text + "' ,const_rate ='" + txtconstrate2.Text + "' ,Plot_value ='" + txtPlotvalue2.Text + "' ,const_value ='" + txtConno2.Text + "' ,total_value ='" + txttotalvalue2.Text + "' ,Remarks ='" + txtRemarks2.Text + "'**,Date2 = '"+ dateshort +"'** WHERE ID=" + ID + "";


    conn.Open();
    cmd.ExecuteNonQuery();
    ResultGridView.EditIndex = -1;
    FillVendorGrid();
    conn.Close();


}

【问题讨论】:

    标签: sql ms-access gridview ms-access-2010


    【解决方案1】:

    至少,日期值的第一个文本表达式应该按照 ISO 序列格式化:

    string dateshort = dt.ToString("yyyy'/'MM'/'dd");
    

    其次,在 Access 中,这些必须包裹在 octothorpes 中:

    "', Date2 = #" + dateshort + "# WHERE ID="
    

    这也必须针对其他日期时间字段进行修改。

    或者,帮自己一个大忙,转而调用参数化查询

    【讨论】:

      猜你喜欢
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 2021-08-16
      相关资源
      最近更新 更多