2
Answers

Upload Monthly data

Photo of yesubabu k

yesubabu k

7y
205
1
Dear Sir,
 
I have  a table its contains EMP_code,date , status
So i need to upload month data in a table 
can any one help to me
 
Excel:
 
Code  1/01/2018  2/01/2018  3/01/2018  4/01/2018    5/01/2018
  1             P              P                P                P                A
  2             P              A                P                P                P
  3             P              P                P                A                P
  4             P              P                P                P                P
  5             P              P                P                P                P
 
Through Excel sheet i have to save in the table
 
 
please help to me sir 
 

Answers (2)

0
Photo of Dharmraj Thakur
NA 4.1k 61.7k 7y
Hellow,
 
1. Create following table in database
 
2. Read one by one rows from excel file.
 
3. Insert in below database tables.
 
Database Tables:
 
Employees
ID Name
1 Yesubabu
2 Dharmraj
 
 
Addendances

ID EmployeeID Date Status
1 2 01/01/2018 1
2 2 02/01/2018 1
3 2 03/01/2018 1
4 2 04/01/2018 1
5 2 05/01/2018 0
6 1 01/01/2018 1
7 1 02/01/2018 0
8 1 03/01/2018 1
9 1 04/01/2018 1
10 1 05/01/2018 1
 
0
Photo of Altaf Ansari
NA 1.4k 27.4k 7y
Try This :
 
  1. private DataTable GetTableDataXl(string XlFile)  
  2.       {  
  3.           DataTable dt = new DataTable();  
  4.           try  
  5.           {  
  6.               string Ext = Path.GetExtension(XlFile);  
  7.               string connectionString = "";  
  8.               if (Ext == ".xls")  
  9.               {   //For Excel 97-03  
  10.                   connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + XlFile + "; Extended Properties = 'Excel 8.0;HDR=YES'";  
  11.               }  
  12.               else if (Ext == ".xlsx")  
  13.               {    //For Excel 07 and greater  
  14.                   connectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source =" + XlFile + "; Extended Properties = 'Excel 8.0;HDR=YES'";  
  15.               }  
  16.               OleDbConnection conn = new OleDbConnection(connectionString);  
  17.               OleDbCommand cmd = new OleDbCommand();  
  18.               OleDbDataAdapter dataAdapter = new OleDbDataAdapter();  
  19.   
  20.               cmd.Connection = conn;  
  21.               //Fetch 1st Sheet Name  
  22.               conn.Open();  
  23.               DataTable dtSchema;  
  24.               dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);  
  25.               string ExcelSheetName = dtSchema.Rows[2]["TABLE_NAME"].ToString();  
  26.               conn.Close();  
  27.               //Read all data of fetched Sheet to a Data Table  
  28.               conn.Open();  
  29.               cmd.CommandText = "SELECT * From [" + ExcelSheetName + "]";  
  30.               dataAdapter.SelectCommand = cmd;  
  31.               dataAdapter.Fill(dt);  
  32.               conn.Close();  
  33.           }  
  34.           catch (Exception ex)  
  35.           { }  
  36.   
  37.           return dt;  
  38.       }