Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello SIr
please help me. I want to split the cell of excel and save it into different columne.
I want to split column: 111000/2008 .
I want to save registration number=111000
passing year:2008.



Please help. I need to save it in database
Posted
Updated 15-Apr-15 4:31am
v2
Comments
Maciej Los 15-Apr-15 10:13am    
Passing year 2007? I see: 111000/2008...
Aone starteam 15-Apr-15 10:31am    
its 2008
Maciej Los 15-Apr-15 10:38am    
Please, see my answer ;)

1 solution

Steps to do:
1. Create OleDbConnection[^] and use ConnectionString[^] as follow:
C#
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";

2. Create OleDbCommand:
SQL
SELECT LEFT([FieldNameOrColumnNo], LEN([FieldNameOrColumnNo]-5) AS RegNo,
    RIGHT([FieldNameOrColumnNo], 4) AS PassYear
FROM [SheetName$]

3. Create and Execute OleDbReader[^]
4. Create DataTable[^] and load data into it from OleDbReader[^].
5. That's all!
 
Share this answer
 
v2
Comments
Aone starteam 15-Apr-15 11:00am    
i have 8 column in that excelsheet
Maciej Los 15-Apr-15 11:06am    
So what? Just add another columns into select statement...
Aone starteam 15-Apr-15 11:11am    
Thanks........ I will try it
Aone starteam 16-Apr-15 3:56am    
Thanks its works
Maciej Los 16-Apr-15 4:56am    
You're very welcome ;)

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