hi all,
I ant to transfer Excel data to SQL server 2005, i have done it using this code ----
OleDbConnection ExcelCon = ExcelConnection(FileName);
OleDbCommand ExcelCmd = new OleDbCommand("select * from [sheet1$]", ExcelCon);
ExcelCon.Open();
IDataReader eRdr = ExcelCmd.ExecuteReader();
DataTable tb = new DataTable();
tb.Load(eRdr);
SqlConnection myConnection = getSqlConnection();
myConnection.Open();
SqlBulkCopy bulk = new SqlBulkCopy(myConnection);
bulk.DestinationTableName = ctrlDestination.SelectedValue;
if(Session["columnmap"] != null)
{
ColumnMapping = Session["columnmap"] as Hashtable;
foreach (DictionaryEntry de in ColumnMapping)
{
bulk.ColumnMappings.Add(de.Key.ToString(), de.Value.ToString());
}
}
try
{
bulk.WriteToServer(tb);}
But im getting exception as "pload Data
The given value of type String from the data source cannot be converted to type
smallint of the specified target column."
Wats the problem, plz suggest solution
Thank you,