Try the following:
StringBuilder hobbies = new StringBuilder();
if (chkcricket.IsChecked==true)
{
hobbies.Append("cricket,");
}
if (chkhockey.IsChecked == true)
{
hobbies.Append("hockey,");
}
if (chkbasketball.IsChecked == true)
{
hobbies.Append("basketball,");
}
if (chkother.IsChecked == true)
{
hobbies.Append("other");
}
SqlCommand cmd = new SqlCommand("insert into record(name,id,hobbies) values(@name,@id,@hobbies)",con);
cmd.Parameters.AddWithValue("@name", txtname.Text);
cmd.Parameters.AddWithValue("@id", txtId.Text);
cmd.Parameters.AddWithValue("@hobbies", hobbies.ToString());
I have used a stringbuilder to build the hobbies string (it is not the cleanest way to do it as over time you will have to keep extending that if statements collection.
I have also introduced Parameters into the SQL query to help prevent SQL Injection attacks.