当我想从访问中检索日期时,我在 cmd1.ExecuteReader 处收到异常错误“没有给出一个或多个参数的值”。这是我的代码
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:中心 show_date_picker:for_dates
因为我是c#的新手,请帮帮我
答案 0 :(得分:1)
您的查询中没有任何参数
这意味着您的一个或多个字段名称
Open Date
或Close Date
在您的表事件中不存在
答案 1 :(得分: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";
}
我做了一些修改,我执行了一个读者,关闭它,然后执行第二个。