It works fine when i select all the data from the database and display it. But when i want to specifically display certain data from the database, that error would show up. (System.Data.OleDb.OleDbException: 'No value given for one or more required parameters.' )
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();
}
you need to add parameter to your select
string selectoledb = "Select * from items where Categories=@Fitems";
command.Parameters.Add("@Fitems", SqlDbType.Varchar).Value = Fitems.Text; //or value you want to filter
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.