private void Form1_Load(object sender, EventArgs e) { // create and use database form to get database // connection details DatabaseForm databaseFrm = new DatabaseForm(); databaseFrm.ShowDialog(); // create connection string for particular database // (from database form) string connStr = DatabaseForm.sConnStr; myConn = new MySqlConnection(connStr); // create a query string string sqlStr = "SELECT * FROM snakegame"; // create a data adapter object with the specified // connection and query MySqlDataAdapter dAdapter = new MySqlDataAdapter(sqlStr, connStr); // fill the data table and close the connection dAdapter.Fill(dTable); dAdapter.Dispose(); if (sname == "" || fname == "") { PlayerDetails playerform = new PlayerDetails(); playerform.ShowDialog(); } }
private void Scoreboard_Load(object sender, EventArgs e) { // create and use database form to get database // connection details DatabaseForm databaseFrm = new DatabaseForm(); // create connection string for particular database // (from database form) string connStr = DatabaseForm.sConnStr; // create connecting myConn = new MySqlConnection(connStr); // create query string to display all records //initially string sQuery = "SELECT * FROM snakegame"; // Call helper function to load data updateDataGrid(sQuery); // Fill datagrid dgvsnakegame.DataSource = dTable; dgvsnakegame.Columns[0].HeaderText = "playerid"; dgvsnakegame.Columns[1].HeaderText = "firstname"; dgvsnakegame.Columns[2].HeaderText = "surname"; dgvsnakegame.Columns[3].HeaderText = "duration"; dgvsnakegame.Columns[4].HeaderText = "gamescored"; dgvsnakegame.Columns[0].ReadOnly = true; }