C# BulkCopy with SQL Server Compact Edition, is it possible? -
this question has answer here:
- sqlbulkcopy using sql ce 4 answers
my intent copy excel data sql server compact edition.
i have read difference between sql server compact , sql server here couldn't find out.
also, know constructor of sqlbulkcopy takes parameter of sqlconnection , not sqlceconnection.
here code:
public void importdatafromexcel(string excelfilepath) { string ssqltable = "inflations"; string myexceldataquery = "select cusip,fm,tnt,cpi_index [sheet1$]"; string sexcelconnectionstring = @"provider=microsoft.jet.oledb.4.0;data source=" + excelfilepath + ";extended properties=" + "\"excel 8.0;hdr=yes;\""; string ssqlconnectionstring = "data source=c:\\users\\abc\\documents\\datafile.sdf;password=12345;"; oledbconnection oledbconn = new oledbconnection(sexcelconnectionstring); oledbcommand oledbcmd = new oledbcommand(myexceldataquery, oledbconn); oledbconn.open(); oledbdatareader dr = oledbcmd.executereader(); sqlbulkcopy bulkcopy = new sqlbulkcopy(ssqlconnectionstring); bulkcopy.destinationtablename = ssqltable; while (dr.read()) { bulkcopy.writetoserver(dr); } oledbconn.close(); }
Comments
Post a Comment