i have error in query
If you add static strings to your SELECT Statement you always have to surround them on both sides with single ticks.

But you should urgently consider prepared statements like
https://docs.microsoft.com/de-de/dotnet/api/system.data.sqlclient.sqlcommand.prepare?view=netframework-4.8

String insertQuery = "insert into exam_add
  (id,session_id,Title,From_date,To_date,class_id,is_Post,is_Lock) 
select 
   '"+id+ "'
   ,s.session
   ,'" + title.Text+"'
   ,'"+ from.Value.Date.ToString("yyyy-MM-dd")+"'
   ,'"+to.Value.Date.ToString("yyyy-MM-dd")+ "'
   , c.class_name
   ,'"+x+"'
   ,'"+x+"' 
 from year_session s, classes c 
 where s.id = '1' and c.id='" + cls + "'";