当我从数据库中选择所有数据并显示它时,它工作正常。但是,当我想专门显示数据库中的某些数据时,就会出现该错误。 (System.Data.OleDb.OleDbException:'未为一个或多个必需参数提供值。)
private void button1_Click(object sender, EventArgs e)
{
string selectoledb = "Select * from items where Categories=Fitems";
command = new OleDbCommand(selectoledb, connection);
da = new OleDbDataAdapter(command);
DataTable table = new DataTable();
itemstxt.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
itemstxt.RowTemplate.Height = 120;
itemstxt.AllowUserToAddRows = false;
da.Fill(table);
itemstxt.DataSource = table;
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
imageColumn = (DataGridViewImageColumn)itemstxt.Columns[3];
imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
DataGridViewButtonColumn button = new DataGridViewButtonColumn();
button.HeaderText = "Buttons";
button.Name = "button";
button.Text = "Add to cart";
button.UseColumnTextForButtonValue = true;
itemstxt.Columns.Add(button);
da.Dispose();
}
答案 0 :(得分:0)
您需要将参数添加到您的选择
string selectoledb = "Select * from items where Categories=@Fitems";
command.Parameters.Add("@Fitems", SqlDbType.Varchar).Value = Fitems.Text; //or value you want to filter