I just start learning programming and am trying to input data to sql table however, No data is inputted to ms sql for my code in C#, heres my code:
private void button5_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection())
{
using (SqlCommand cmd = new SqlCommand())
{
try
{
conn.ConnectionString = "Data Source=DIT-NB1625963\\DIT1625963;" +
"database=ApplicationDevelopmentDB;" +
"integrated security=true";
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO game_table (PlayerScore, DealerScore)" +
"Values (23,21) ";
cmd.ExecuteNonQuery();
richTextBox1.Text = "You have created a new record." + Environment.NewLine;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
richTextBox1.Text = "Something wrong has occurred." + Environment.NewLine;
}
finally
{
conn.Close();
Console.WriteLine("Closed the connection");
}
}
}
}