我有下面的代码,可以将 access 数据库中的数据显示到另一种形式的文本框中。
item items = new item();
Add_Order addorder = new Add_Order();
OleDbCommand cmd = new OleDbCommand("Select * from tblItems WHERE ItemName = @Item", connection);
cmd.Parameters.AddWithValue("@Item", items.ItemName1);
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
cmd.Parameters.AddWithValue("@ItemID", addorder.tbItemID.Text);
cmd.Parameters.AddWithValue("@ItemName", addorder.tbName.Text);
cmd.Parameters.AddWithValue("@ItemPrice", addorder.tbPrice.Text);
OleDbDataReader read = cmd.ExecuteReader();
while (read.Read())
{
addorder.tbItemID.Text = read[0].ToString();
addorder.tbName.Text = read[1].ToString();
addorder.tbPrice.Text = read[2].ToString();
}
addorder.ShowDialog();
connection.Close();
错误说
参数@Item 没有默认值
@Item
但是我已经在这一行中分配了值
cmd.Parameters.AddWithValue("@Item", items.ItemName1);