c# - type conversion from excel sheet to sqlbulkcopy -


. . have excel sheet columns , types given below

| name(string) | age(string) | dob(string) |

similarly have table in db as

| name(string) | age(int) | dob(date) |

i have insert bulk data excel db table.i doing using sqlbulkcopy. gives error

the given value of type string data source cannot converted type datetime of specified target column.

i know error datatypes stuck error. not know method convert types in sqlbulkcopy. . . can please here code

string myexceldataquery = "select * [sheet1$]";  string sexcelconnectionstring = @"provider=microsoft.ace.oledb.12.0;data source=" + excelfilepath + ";extended properties='excel 12.0 xml;hdr=yes;'";  oledbconnection oledbconn = new oledbconnection(sexcelconnectionstring); oledbcommand oledbcmd = new oledbcommand(myexceldataquery, oledbconn); oledbconn.open();  oledbdatareader dr = oledbcmd.executereader();  sqlbulkcopy bulkcopy = new sqlbulkcopy(db); bulkcopy.destinationtablename = "tablename";   while(dr.read()  )  {     bulkcopy.writetoserver(dr);  }   oledbconn.close(); 


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -