Form / listbox and one label

I am trying to write code that pulls the names of the states into a list box, which I have done but then it needs to pull the information from the county table and show in my popLabel State, Population, Largest County, Smallest County.... I really need help, this is my code thus far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Exam2
{
    public partial class Form1 : Form
    {
        string connectionString;
        SqlConnection connection;
        SqlDataAdapter adapter;

        public Form1()
        {
            InitializeComponent();
            InitialDatabaseObjects();
            LoadStateListBox();
            CloseDatabaseoObjects();
        }
        public void InitialDatabaseObjects()
        {
            connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename= C:\\Users\\Lesley Cadden\\OneDrive\\ANDERSON UNIVERSITY\\Spring 2018\\Exam2\\census.mdf; Integrated Security = True; Connect Timeout = 30";
            connection = new SqlConnection(connectionString);
            connection.Open();
        }
        public void CloseDatabaseoObjects()
        {
            connection.Close();
        }
        public void LoadStateListBox()
        {
            string query = "SELECT * FROM state";
            DataTable stateTable;

            stateTable = new DataTable();
            adapter = new SqlDataAdapter(query, connection);
            adapter.Fill(stateTable);

            stateListBox.Items.Clear();
            foreach (DataRow row in stateTable.Rows)
        {
            stateListBox.Items.Add(row[1]);
        }
          
           
        }
    }
}
Topic archived. No new replies allowed.