D
D
Dmitry Korolev2017-11-04 23:07:05
C++ / C#
Dmitry Korolev, 2017-11-04 23:07:05

How to get the id value knowing one of the record parameters?

How to find out the record id knowing the variable in the record?

command = new SqlCommand("SELECT * FROM [Recent] WHERE [LibraryId] = @LibraryId", sqlConnection);//не знаю
            byte _id = 0;
            try
            {
                _id = Convert.ToByte(command.ExecuteScalar());
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message + "  2   " + exc.Source);
                _id = 0;
            }
            finally
            {
                if (_id != 0)
                {
                    command = new SqlCommand("DELETE FROM [Recent] WHERE [Id] = @Id", sqlConnection);
                    command.Parameters.AddWithValue("Id", _id);
                    await command.ExecuteNonQueryAsync();
                }
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Johnny Gat, 2017-11-05
@adressmoeistranici

command = new SqlCommand("SELECT [Id] FROM [Recent] WHERE [LibraryId] = @LibraryId", sqlConnection);
command.Parameters.AddWithValue("LibraryId", вашеЗначение);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question