.net - C# and excel automation, how to use the CopyFromRecordset function -
.net - C# and excel automation, how to use the CopyFromRecordset function -
i trying populate excel file info sql server,
my code follows,
public static void sqltoexcel(excel.workbook xlworkbook, string sql, string tformat) { string connectionstring = configurationmanager.connectionstrings["ansicconnection"].connectionstring; sqlconnection conn; conn = new sqlconnection(connectionstring); conn.open(); using (sqlcommand cmd = new sqlcommand(sql, conn)) { sqldatareader reader = cmd.executereader(); if (reader.hasrows) { reader.read(); ((range)xlworkbook.sheets["cover"].range("d6")).copyfromrecordset(reader); } reader.close(); } conn.close(); }
i next error
{"no such interface supported (exception hresult: 0x80004002 (e_nointerface))"}
do need convert reader array?
c# .net excel-automation
Comments
Post a Comment