adamo ski
adamo ski

Reputation: 17

Select items which exist in database | C#

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

Answers (1)

Chetan
Chetan

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

Related Questions