code to write table to connection