我想知道如何使用列表视图和按钮从数据库中的表中删除一行。使用列表视图从数据库中的表中删除行
我的代码
private void deleteitems()
{
//DELETE FROM Tbl_Cashier WHERE RecpieId = @RecpieId AND IngredientId = @IngredientId
string query = "delete from Tbl_Cashier where Cashier_ID = '" + listView1.SelectedIndices+"' ";
using (SqlConnection connection = new SqlConnection(connectionString1))
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();
command.Parameters.Remove(listView1.SelectedIndices);
command.ExecuteNonQuery();
connection.Close();
}
MessageBox.Show("You will see the new data with your next restart of the application", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
我收到此错误:
An unhandled exception of type 'System.InvalidCastException' occurred in System.Data.dll
Additional information: The SqlParameterCollection only accepts non-null SqlParameter type objects, not SelectedIndexCollection objects.