Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am using C# windows application for importing the data from Excel cells into SQL server 2008. but while importing some data is perfectly imported but some cells data is cutting. due to that some data is lost. please give solution for this issue.

Thank you.
Posted
Comments
ArunRajendra 27-Jun-13 7:37am    
Is the data lost random or there is any specific pattern whil trucating?
Ganeshh2 27-Jun-13 7:47am    
Hi ArunRajendra,
data lost randomly. some cells data is perfectly imported but some are not imported perfectly..
ArunRajendra 28-Jun-13 0:13am    
Can you show the code how you are importing the data from excel?
Ganeshh2 28-Jun-13 0:32am    
{string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";Extended Properties=Excel 12.0";
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
connection.Open();
DataTable dtSheetName = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
List<string> SubChapters = new List<string>();
SubChapters.Add("--Select--");
int count = 0;
for (int nSheetcount = 0; nSheetcount < dtSheetName.Rows.Count; nSheetcount++)
{
count++;
StringBuilder sSheetNAme = new StringBuilder();
sSheetNAme.Append(dtSheetName.Rows[nSheetcount]["TABLE_NAME"].ToString());
tablename = sSheetNAme.ToString();
string sQuery = "Select * from [" + tablename + "]";
OleDbCommand command = new OleDbCommand(sQuery, connection);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
if (sSheetNAme.ToString().LastIndexOf("'") == sSheetNAme.ToString().Length - 1)
{
sSheetNAme.Remove(sSheetNAme.Length - 2, 2);
sSheetNAme.Replace('#', '.');
}
else
{
sSheetNAme.Remove(sSheetNAme.Length - 1, 1);
sSheetNAme.Replace('#', '.');
}

if (sSheetNAme.ToString().IndexOf("'") == 0)
{
sSheetNAme.Remove(0, 1);
}

SubChapters.Add(sSheetNAme.ToString());

DataTable Dsheet = new DataTable();
adapter.Fill(Dsheet);
dataset.Tables.Add(Dsheet);
}
cmdSubChapters.DataSource = SubChapters;
}
Ganeshh2 28-Jun-13 1:10am    
i think it is not imported the data which is having large size i.e greater than 255 characters. Please let me know the solution for importing the large size cell data.

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