Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends, plz help me with this error
My Error is :
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.

My Code:
C#
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");
}

----- Same code is running Fine when i working on VS 2010 and SQL 2005

Now i use VS 2013 and SQL 2012 Then i getting the error.

PLZ give me the error free code.
Posted
Updated 24-Jun-14 22:37pm
v2

Look at your database definition: the column you are writing to is not big enough to hold all the data you are trying to write into it. One or more columns is too short: it's set as VARCHAR(50) and you are writing 61 characters, or similar.

We can't do that for you: we don't have access to your HDD, or your DB, or your spreadsheet...
 
Share this answer
 
Comments
Thomas Daniels 25-Jun-14 4:42am    
+5!
Member 10052303 25-Jun-14 5:21am    
Thanks! It's work.
Nandakishore G N 25-Jun-14 9:45am    
My 5.
The error means that the data you are trying to write is too large for the database column. You can solve this by increasing the size of the column where you copy the datatable to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900