Newly Inserted Record was not Queried, Immediately after Insertion
You can simply check against inserted id. If insert successful means you get inserted id only then you render the data otherwise do nothing

$inserted_id = db_insert('studidtemplates',array('target' =&gt; 'import')) 
        -&gt;fields(array(         
            'template_name' =&gt; 'WEW',            
            'date_created' =&gt; date("Y-m-d H:i:s", time()),
            'user_name' =&gt; $user-&gt;name
        ))       
        -&gt;execute();
if($inserted_id) {
   return array(
    '#type' =&gt; 'ajax',
    '#commands' =&gt; array(            
        ajax_command_replace('#myid_templates_editor_table_wrapper',     render($form['myid_templates_editor_table_wrapper'])),  

    )
); 
}