获取错误 oledbexception 未处理附加信息:没有为一个或多个必需参数提供值
getting a error oledbexception was unhandled Additional information: No value given for one or more required parameters
我在尝试 select 数据库中的数据时遇到此错误,我不知道如何修复它。我的查询在我的数据库中有效,但我不确定发生了什么
randomget = "SELECT top 1 id, Department, Team, Process, SubProcess, SubTask, LastUpdatedBy from workload where stepstatus = 'complete' and agent is null or agent = 0 ";
OleDbConnection MyConn = new OleDbConnection();
MyConn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=.......;Persist Security Info=False";;
MyConn.Open();
OleDbCommand cmd = MyConn.CreateCommand();
cmd.CommandText = randomget;
OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
int id = 0;
while (reader.Read())
{
id = int.Parse(reader[0].ToString());
textBox8.Text = reader[6].ToString();
textBox5.Text = reader[1].ToString();
textBox6.Text = reader[2].ToString();
textBox7.Text = reader[3].ToString();
textBox9.Text = reader[4].ToString();
textBox11.Text = reader[5].ToString();
break;
}
// input table name here
textBox2.Text = agentsrf.ToString();
string sqlupdate = "Update workload set agent = '" + agent + "', where ID = " + id + " ' ";
}
public OleDbConnection connection { get; set; }
在 set agent = '" + agent + "'
之后你有一个杂散的 ,
只需将其删除,然后它就可以正常工作。你也应该使用 parameterized queries because this kind of string concatenations are open for SQL Injection:
string sqlupdate = "Update workload set agent = @agent where ID = @id ";
cmd.Parameters.AddWithValue("@agent", agent );
cmd.Parameters.AddWithValue("@id", id);
我解决了。我的一个字段名称中有一个 space,我没有发现它。
我在尝试 select 数据库中的数据时遇到此错误,我不知道如何修复它。我的查询在我的数据库中有效,但我不确定发生了什么
randomget = "SELECT top 1 id, Department, Team, Process, SubProcess, SubTask, LastUpdatedBy from workload where stepstatus = 'complete' and agent is null or agent = 0 ";
OleDbConnection MyConn = new OleDbConnection();
MyConn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=.......;Persist Security Info=False";;
MyConn.Open();
OleDbCommand cmd = MyConn.CreateCommand();
cmd.CommandText = randomget;
OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
int id = 0;
while (reader.Read())
{
id = int.Parse(reader[0].ToString());
textBox8.Text = reader[6].ToString();
textBox5.Text = reader[1].ToString();
textBox6.Text = reader[2].ToString();
textBox7.Text = reader[3].ToString();
textBox9.Text = reader[4].ToString();
textBox11.Text = reader[5].ToString();
break;
}
// input table name here
textBox2.Text = agentsrf.ToString();
string sqlupdate = "Update workload set agent = '" + agent + "', where ID = " + id + " ' ";
}
public OleDbConnection connection { get; set; }
在 set agent = '" + agent + "'
之后你有一个杂散的 ,
只需将其删除,然后它就可以正常工作。你也应该使用 parameterized queries because this kind of string concatenations are open for SQL Injection:
string sqlupdate = "Update workload set agent = @agent where ID = @id ";
cmd.Parameters.AddWithValue("@agent", agent );
cmd.Parameters.AddWithValue("@id", id);
我解决了。我的一个字段名称中有一个 space,我没有发现它。