At the moment I'm trying to populate my SQL Server database with 3 values I'm hard coding in through a C# program.
My database has 4 columns which are as follows:
RowID
(this should get updated automatically by my database)Name
(stored as a string)Score
(int)Accuracy
(float)
In my code I'm trying to fill these out with the following lines of code:
using (SqlConnection connection = new SqlConnection(DBConnection))
{
string name = "John";
int score = 123;
float Accuracy = 20.0f;
SqlCommand command = new SqlCommand("INSERT INTO HighScoreTable(Name, Score, Accuracy) VALUES(" + name + " , " + score + " , " + Accuracy + ")", connection);
command.Connection.Open();
command.ExecuteNonQuery();
}
But when I run my program, Visual Studio highlights
command.ExecuteNonQuery()
stating ' John' is not a valid column.
Is there something I'm doing wrong with this?