An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code Additional information: The given value of type String from the data source cannot be converted to type nchar of the specified target column. String or binary data would be truncated.
protected void Button1_Click(object sender, EventArgs e) { String strConnection = @"Data Source=MANOJ\SQLEXPRESS;Initial Catalog=MANOJ;Integrated Security=True"; string path = @"C:\Users\Manoj Kumar\Desktop\Update Folder\TESTING.xlsx"; //Create connection string to Excel work book string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\""; //Create Connection to Excel work book OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); OleDbCommand cmd = new OleDbCommand("select *from [Sheet1$]", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection); //Give your Destination table name sqlBulk.DestinationTableName = "TEST"; sqlBulk.WriteToServer(dReader); // Here i getting the above error excelConnection.Close(); Response.Write("inserted"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)