Reputation: 17
how could I select / check items in checkedListBox which exist in database ?
I INSERT value to Table (Tickets): (PK TicketID, FK ShowID, FK PriceID, Seat )
INSERT is ok, now I want to check this items which aleady exist in DB.
I have no idea to solve this problem.
EDIT: I want to select Items which exist in database, so it's not solve my problem I think.
Upvotes: 0
Views: 79
Reputation: 6891
You can write code something like below.
using(var connection = new SqlConnection(<<connectionString>>))
{
var sqlQuery = <<Select Query>>;
connection.Open();
using(var command = new SqlCommand(sqlQuery, connection))
{
var count = (int) comand.ExecuteScalar();
if(count > 0)
{
//Logic of selecting checkbox in the checkbox list.
}
}
}
Upvotes: 1