I am trying to use using in c# when inserting etc... Be course many have recommended me to.
But it keeps saying the error: Format of the initialization string does not conform to specification starting at index 0. (Translated from Danish)
My code:
protected void BTN_reg_Click(object sender, EventArgs e)
{
string connectionString = "ConnectionString";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Users (Username, Password, Name, Role_id, Email, Sub, Acc) VALUES (@username, @pass, @name, @role, @email, @sub, @Acc);";
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@username", TB_reg_username.Text);
cmd.Parameters.AddWithValue("@pass", TB_reg_pass.Text);
cmd.Parameters.AddWithValue("@name", TB_reg_name.Text);
cmd.Parameters.AddWithValue("@role", 2);
cmd.Parameters.AddWithValue("@email", TB_reg_email.Text);
cmd.Parameters.AddWithValue("@sub", CheckBox1.Checked);
cmd.Parameters.AddWithValue("@Acc", "False");
connection.Open();
cmd.ExecuteNonQuery();
}
}