private void button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Server=.;Integrated Security=true;...";
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "Select * From Table_Name";
command.CommandType = CommandType.Text;
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
string title = (string)reader["Title"];
string description = (string)reader["description"];
string item = string.Format("{0} - {1}", title, description);
this.listBox1.Items.Add(item);
}
reader.Close();
}
catch
{
}
finally
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
}