exceptive
Looking for a logging solution
private void LoadData(string connectionString)
{
string query = "SELECT * FROM railroad";
try
{
using (var connection = new SqlConnection(connectionString))
using (var adapter = new SqlDataAdapter(query, connection))
{
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
if (dataTable.Rows.Count > 0)
{
dataGridView1.DataSource = dataTable;
}
else
{
MessageBox.Show("No data found in the table.", "No Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show($"Error loading data: {ex.Message}", "Data Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
9 replies