Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

Anyone please help me and tell me how to resolve the issues mentioned below:

I got an Excel sheet. I need to read data from excel sheet. Fields are manufacturer, partnumber, description, and price. I need help to read the data from Excel sheet and store it in a sqlserver database based on the manufacturer and partnumber.

I was trying to implement the logic but when I read the data from excel sheet and assign it into dataset i face issues.
Issue 1:
The row count 2754 is shown, but in my excel sheet only 5 rows are available.

OleDbConnection oledbCon = new OleDbConnection(strCon);
oledbCon.Open();
OleDbCommand oledbCmd = oledbCon.CreateCommand();
oledbCmd.CommandText = "SELECT * FROM [Sheet1$]";
DataSet ds = new DataSet();
OleDbDataAdapter oledbDa = new OleDbDataAdapter(oledbCmd);
oledbDa.Fill(ds, "TempExcel");
ds.Tables[0].Rows.Count

Issue 2:
If price fields in Excel sheet contains alphabet leter, when I fetch the record from price field it shows null value.
Posted
Updated 22-Jun-10 20:38pm
v3

Can you try IMEX=1 extended property in connection string to solve the second issue.
 
Share this answer
 
Comments
sethupathiram 23-Jun-10 3:08am    
Hi Thanks....
Your temp table is created based on the values found in the
columns. It appears your price column is being created,
not without cause, as a numeric field. So when the attempt
is made to insert the price value that has a letter in it, the insert fails. Instead of "Select *", try casting the price column into
a char or varchar. That should solve the missing price issue. The first issue requires a where clause against a value you know is always present (where partnumber is not null or where len(partnumber)>0)
 
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