im making a WF where i get to insert soccer results, however the team winning should get 3, the losing team 0, if its a draw both should get 0.
i have a DB called voetbaldb, with a table called teams, where the scores of the teams should be updated, with 3 columns called ID which is primary key, teamname and teamrank which is unique.
so far i get to insert the results in the database into a different table called 'uitslagen' which is results just to clear it up.
this is my code, however i just cant get it work, i cant find away to give the winnning team the points it deserves:
namespace SportApp
{
public partial class AddResults : Form
{
public AddResults()
{
InitializeComponent();
}
string connstring = "Server=localhost;Port=3307;Database=voetbaldb;Uid=root;Pwd=usbw;";
private void add_result_button_Click(object sender, EventArgs e)
{
try
{
string query = "INSERT INTO uitslagen (hometeam, awayteam, homescore, awayscore) VALUES ('" + txt_box_home_team.Text + "', '" + txt_box_away_team.Text + "', '" + txt_box_home_score.Text + "', '" + txt_box_away_score.Text + "')";
MySqlConnection conn = new MySqlConnection(connstring);
MySqlCommand cmd = new MySqlCommand(query, conn);
conn.Open();
MySqlDataReader reader = cmd.ExecuteReader();
conn.Close();
MessageBox.Show("The result has been added!");
txt_box_home_team.Text = "";
txt_box_away_team.Text = "";
txt_box_home_score.Text = "";
txt_box_away_score.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
if (txt_box_home_score.Text > txt_box_away_score.Text)
{
UPDATE teams SET teamrank = (SELECT ISNULL(MAX(teamrank), 0) + 1 FROM teams)
}
if else (txt_box_home_score.Text < txt_box_away_score.Text)
{
UPDATE teams SET teamrank = (SELECT ISNULL(MAX(teamrank), 0) + 1 FROM teams)
}
else (txt_box_home_score.Text == txt_box_away_score.Text)
UPDATE teams SET teamrank = (SELECT ISNULL(MAX(teamrank), 0) + 1 FROM teams)
}
}
}
Aucun commentaire:
Enregistrer un commentaire