Соединение выполняется с использованием строки соединения и класса SqlConnection
- что, похоже, подходит для вашего кода.
НО : то, как вы пытаетесь вставить значения, совершенно неверно - вам нужно использовать что-то вроде этого:
using (SqlConnection sqlCon = new SqlConnection(connectionstring))
{
sqlCon.Open();
// SPECIFY the column you insert into!
// Without the @ "query" is not recognized as a multiline string... that's why the PO is getting that VALUES does not exists in the current context...
string query = @"INSERT INTO Employee (ID, Name, City, Address)
VALUES (@ID, @Name, @City, @Address)";
for (int i = 0; i <= 100; i++)
{
SqlCommand sqlcmd = new SqlCommand(query, sqlCon);
// set the individual parameters, and AVOID "AddWithValue"
sqlcmd.Parameters.Add("@ID", SqlDbType.Int).Value = i;
sqlcmd.Parameters.Add("@Name", SqlDbType.VarChar, 100).Value = "newride";
sqlcmd.Parameters.Add("@City", SqlDbType.VarChar, 100).Value = "newride";
sqlcmd.Parameters.Add("@Address", SqlDbType.VarChar, 100).Value = "USA";
// and then *EXECUTE* the SqlCommand to actually RUN the INSERT
sqlcmd.ExecuteNonQuery();
}
}