Click here to Skip to main content
15,867,921 members
Please Sign up or sign in to vote.
1.00/5 (6 votes)
See more:
SQL
SqlConnection dbConnection;
        SqlCommand dbCommand;
        DataSet ds;
        SqlDataAdapter dbAdapter;
        SqlDataReader dbread;

        public GamesforCountry(SqlConnection dbConnection)
        {
            this.dbConnection = dbConnection;
            InitializeComponent();
        }

        private void GamesforCountry_Load(object sender, EventArgs e)
        {
            dbCommand = new SqlCommand("SELECT * FROM Country",dbConnection);
            dbAdapter = new SqlDataAdapter(dbCommand);
            ds = new DataSet();
            dbAdapter.Fill(ds, "GamesFor");
            cboCountryName.DataSource = ds.Tables["GamesFor"];
            cboCountryName.DisplayMember = "CountryName";
            cboCountryName.ValueMember = "CountryId";
        }

        private void cboCountryName_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (dbConnection.State == ConnectionState.Closed)
            {
                dbConnection.Open();
            }
            dbCommand = new SqlCommand("SELECT Game.GameId,CountryName,Location,Date,Time FROM Game,Results,Country WHERE Results.CountryId = Country.CountryId AND Game.GameId = Results.GameId AND Country.CountryName ='" + cboCountryName.SelectedValue + "'", dbConnection);

            dbAdapter = new SqlDataAdapter(dbCommand);
            ds = new DataSet();
            dbAdapter.Fill(ds, "view");
            dgvGamesforCountry.DataSource = ds.Tables["view"];
Posted
Updated 11-Oct-11 11:37am
v2
Comments
Richard MacCutchan 11-Oct-11 17:37pm    
Do you have a question?
Sergey Alexandrovich Kryukov 11-Oct-11 18:17pm    
Please don't post just code. If you have a problem, please explain it. Use "Improve question".
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900