I have the following code:
public static void dbInfoInsert(int ID)
{
try
{
SqlConnection sqlCon = new SqlConnection(@"Data Source = (local); Initial Catalog = myDB; Integrated Security = True;");
sqlCon.Open();
SqlCommand insert = new SqlCommand
{
CommandText = string.Format("INSERT INTO [dbo.Food] ([FoodID], [FoodName], [FoodPrice], [FoodDescription]) VALUES ({0}, {1}, {2}, {3})", "T001", "FoodName", 23, "Food"),
Connection = sqlCon
};
insert.ExecuteNonQuery();
Console.Clear();
Console.WriteLine("SUCCESS");
Console.ReadKey();
sqlCon.Close();
}
// In case connection to Microsoft SQL fails
catch (SqlException e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
}
}
The error says that I have an Invalid column name 'T001'
, but that isn't my column. Am I doing something wrong here? In my database which name is myDB
, I have a dbo.Food
table which contains the following columns:
- FoodID varchar(10)
- FoodName varchar(100)
- FoodPrice money
- FoodDescription varchar(1000)