I keep getting the following error: (C# WinForms)
"Invalid syntax near ','"
I have the following code:
// Initialize and instantiate a new reader object.
SqlDataReader slrr = null;
// Send command.
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("SELECT ActivationCode FROM CAccounts WHERE ActivationCode=" +
_activationcode, connection);
slrr = command.ExecuteReader();
// read result(s) of command.
while (slrr.Read())
{
if (slrr["ActivationCode"].ToString() == _activationcode.Text)
{
stat.Text = "It appears that these details have already been registered.";
Properties.Settings.Default.GU = false;
Properties.Settings.Default.Save();
}
else
{
System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(
"INSERT INTO CAccounts (FirstName, LastName, Country, Gender, EmailAddress, ActivationCode, ClientID, IsActivated) VALUES ('" +
_firstname.Text + "', '" + _lastname.Text + "', '" + _country.Text + "', '" + gender + "', '" +
_email.Text + "', '" + _activationcode.Text + "', '" + _clientid.Text + "', '" + "yeh'", connection);
comm.ExecuteNonQuery();
stat.Text = "Product Activation succeeded.";
Properties.Settings.Default.GU = true;
Properties.Settings.Default.FirstName = _firstname.Text;
Properties.Settings.Default.LastName = _lastname.Text;
Properties.Settings.Default.Country = _country.Text;
Properties.Settings.Default.Gender = gender;
Properties.Settings.Default.DateOfBirth = _dateofbirth.Text;
Properties.Settings.Default.EmailAddress = _email.Text;
Properties.Settings.Default.ActivationID = _activationcode.Text;
Properties.Settings.Default.ClientID = _clientid.Text;
Properties.Settings.Default.IsActivated = true;
Properties.Settings.Default.Save();
}
}
}
catch (Exception exception)
{
// Catch the exception and throw an error.
stat.Text = exception.Message;
}
I have absolutely no idea what I've done wrong. Can somebody please help me?