string levelofdisater;
string connectionString = "Server=serverAdi;Database=veritabaniAdi;User Id=kullaniciAdi;Password=sifre;";
// SQL sorgusu
string query = $"SELECT derece FROM Depremler WHERE İl = {comboBox1.SelectedItem.ToString()}";
// Bağlantı oluşturma ve komut oluşturma
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(query, connection))
{
// Parametre ekleme
command.Parameters.AddWithValue("@İl", "ilAdi");
try
{
// Bağlantıyı açma
connection.Open();
// Veri okuma
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
// Her bir dereceyi ekrana yazdırma
levelofdisater = reader["Risk"];
}
}
}
catch (Exception ex)
{
Console.WriteLine("Hata: " + ex.Message);
}
}