Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public partial class EnterResults : Form
    {

        SqlConnection dbConnection;
        SqlCommand dbCommand;
        DataSet dsResults;
        SqlDataAdapter dbAdapter;

        public EnterResults()
        {
            InitializeComponent();
        }

        private void EnterResults_Load(object sender, EventArgs e)
        {
            dbConnection = new SqlConnection("Initial Catalog = Rugby_World_Cup; Data Source = localhost; Integrated Security= True");

            dbCommand = new SqlCommand("SELECT * FROM Game", dbConnection);
            dbAdapter = new SqlDataAdapter(dbCommand);
            dsResults = new DataSet();
            dbAdapter.Fill(dsResults, "Result");
            cboGameID.DataSource = dsResults.Tables["Result"];
           cboGameID.DisplayMember = "GameId";
                     cboGameID.SelectedIndex = -1;



        }

        private void btnEnter_Click(object sender, EventArgs e)
        {
            if (dbConnection.State == ConnectionState.Closed)
            {
                dbConnection.Open();
            }

            dbCommand = new SqlCommand("EnterGame", dbConnection);
            dbCommand.CommandType = CommandType.StoredProcedure;

            dbCommand.Parameters.AddWithValue("@GameID", cboGameID.SelectedValue.ToString());
            dbCommand.Parameters.AddWithValue("@CountryID", cboCountryID.SelectedValue.ToString());
            dbCommand.Parameters.AddWithValue("@Tries", txtTries.Text);
            dbCommand.Parameters.AddWithValue("@Penalty", txtPenalties.Text);
            dbCommand.Parameters.AddWithValue("@DropG", txtDropGoals.Text);
            dbCommand.Parameters.AddWithValue("@Points", txtPoints.Text);

            if (dbCommand.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("Results where Entered");
            }
            cboGameID.SelectedIndex = -1;
            cboCountryID.SelectedIndex = -1;
            txtDropGoals.Clear();
            txtPenalties.Clear();
            txtPoints.Clear();
            txtTries.Clear();
            cboGameID.Focus();

        }

        private void cboGameID_SelectedIndexChanged(object sender, EventArgs e)
        {

    
            
                dbCommand = new SqlCommand("Select * from game", dbConnection);
                dbCommand.Parameters.AddWithValue("@ID",cboGameID.SelectedValue.ToString());
                dbAdapter = new SqlDataAdapter(dbCommand);
                dsResults = new DataSet();
                dbAdapter.Fill(dsResults, "enter");
                cboCountryID.DataSource = dsResults.Tables["enter"];
                cboCountryID.DisplayMember = "CountryId";
                           cboCountryID.SelectedIndex = -1;
            
        }
    }
}
Posted
Updated 10-Oct-11 11:05am
v2
Comments
DaveAuld 10-Oct-11 17:07pm    
Why did you post 3 questions with 3 different body contents? I have deleted the other 2. If you need to update the question, use the 'Improve question' at the bottom right of the text area.
luisnike19 10-Oct-11 17:07pm    
Where is your question/problem?

1 solution

You can write the code in simple, elegant and powerful way using LInQ in .NET 3.5

C#
var GamenName = from game in dbContext.Games
                where game.CountryId == cboCountryID.SelectedIndex.ToString()
                select game.name;
 
Share this answer
 

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