In run mode i click th export button and debug and shows error as follows
The given value of type String from the data source cannot be converted to type int of the specified target column.
how to solve this error.
protected void btnexport_Click(object sender, EventArgs e)
{
if (!FileUpload1.HasFile)
{
string CurrentFilePath = string.Concat(Server.MapPath("~/masterdata/Test1.xlsx" + FileUpload1.FileName));
FileUpload1.SaveAs(CurrentFilePath);
string constr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", CurrentFilePath);
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = constr;
OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
connection.Open();
System.Data.Common.DbDataReader dr = command.ExecuteReader();
string sqlConnectionString = @"Data Source = DESKTOP; Initial Catalog = Sample; User ID = sa; Password = 12345";
SqlBulkCopy bulkInsert = new SqlBulkCopy(sqlConnectionString);
bulkInsert.DestinationTableName = "tbl_farmerregistration_ivorycoast";
bulkInsert.WriteToServer(dr);
}
}