2

当我想从 access 中检索日期时,我在cmd1.ExecuteReader收到异常错误“No Value given for a or more parameters” 。这是我的代码

void checking_fields()
    {

        OleDbCommand cmd = new OleDbCommand("select movie_id from event", oc);
        OleDbDataReader ol = cmd.ExecuteReader();
        OleDbCommand cmd1 = new OleDbCommand("select [open date],[close date] from event", oc);
        OleDbDataReader ol1 = cmd1.ExecuteReader();
        while (ol1.Read())
        {
            if (ol1.GetValue(0).ToString() == dateTimePicker1.Value.ToString("MM/dd/yyyy") || 
                ol1.GetValue(1).ToString() == dateTimePicker2.Value.ToString("MM/dd/yyyy"))
                goto abc;
        }
        ol.Read();

        if (textBox1.Text.Equals(ol.GetString(0)))
            label8.Text = "ID already exists";
        else
        {
            insert_database();
            clear();
            this.Close();
        }
        abc:  label8.Text = "Open date or Close date already assigned";
        }

这些是打开日期和关闭日期的属性

必需:否,索引:是(无重复),ime_mode:no_control,text_align:center,show_date_picker:for_dates

因为我是 C# 新手,请帮助我

4

2 回答 2

1

您的查询中没有任何参数。
这意味着您的一个或多个字段名称
Open DateClose Date
在您的表事件中不存在

于 2012-06-27T19:29:52.610 回答
0

似乎您还没有打开连接:

void checking_fields()
{

    OleDbCommand cmd = new OleDbCommand("select movie_id from event", oc);
oc.open();

    OleDbDataReader ol1 = cmd1.ExecuteReader();
    while (ol1.Read())
    {
        if (ol1.GetValue(0).ToString() == dateTimePicker1.Value.ToString("MM/dd/yyyy") || 
            ol1.GetValue(1).ToString() == dateTimePicker2.Value.ToString("MM/dd/yyyy"))
            goto abc;
    }
oc.close();

    OleDbCommand cmd1 = new OleDbCommand("select [open date],[close date] from event", oc);
    oc.open();
    OleDbDataReader ol = cmd.ExecuteReader();
    ol.Read(); // consider revising that section

    if (textBox1.Text.Equals(ol.GetString(0)))
        label8.Text = "ID already exists";
    else
    {
        insert_database();
        clear();
        this.Close();
    }
    abc:  label8.Text = "Open date or Close date already assigned";
    }

我做了一些修改,我执行了一个阅读器,关闭它,然后再执行第二个。

于 2012-06-27T11:55:19.033 回答