I don't know what is wrong with this code. It was working just fine before adding radio button. Also what is the use of primary key clustered in SQL Server?
private void createSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\DELL\source\repos\phoneBookwin\phoneBookwin\Database1.mdf;Integrated Security=True");
con.Open();
string value;
bool friendCheck = groupFriends.Checked;
bool familyCheck = groupFamily.Checked;
bool emergencyCheck = groupEmergency.Checked;
bool collCheck = groupColl.Checked;
if (friendCheck)
value = groupFriends.Text;
else if (familyCheck)
value = groupFamily.Text;
else if (emergencyCheck)
value = groupEmergency.Text;
else if (collCheck)
value = groupColl.Text;
else
value = "";
SqlCommand cmd = new SqlCommand("insert into Contacts(Name, Contacts, Email, Group) values('" + createName.Text + "', '" + createNumber.Text + "', '" + createEmail.Text + "','"+value+"')", con);
cmd.ExecuteNonQuery();
this.Hide();
Form1 save = new Form1();
save.ShowDialog();
}
Exception thrown:
Incorrect syntax near keyword 'group'
This is my database table:
CREATE TABLE [dbo].[Contacts]
(
[Name] VARCHAR (50) NOT NULL,
[Contacts] VARCHAR (50) NOT NULL,
[Email] VARCHAR (50) NULL,
[Group] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Name] ASC)
);