Please refer below code.and must check if query returning data
C#
void me()
{
string connectionString = ConfigurationManager.ConnectionStrings["myconstr"].ToString();
SqlConnection connection = new SqlConnection(connectionString);
DataTable dt = new DataTable();
string sql = "INSERT INTO clients (code, sub_code, client_name, cat, email, address," +
"contact_phone, contact_phone2, active_phone, company_id_fk," +
" procdure_id_fk, service_id_fk, procdure_date, user_id_fk," +
" creation_date, transfer_date )" +
"SELECT code, sub_code, client_name, cat, email, address," +
" contact_phone, contact_phone2, active_phone, company_id_fk," +
" procdure_id_fk, service_id_fk, procdure_date, user_id_fk," +
"creation_date, transfer_date" +
" FROM archive_clients WHERE code NOT IN (SELECT code FROM clients )";
try
{
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(dt);
if (dt != null)
{
Response.Write("Number of rows " + dt.Rows.Count.ToString());
}
connection.Close();
}
catch (Exception ex)
{
Response.Write("Error in execution " + ex.ToString());
}
}
I hope this will help you out.