Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have created a folder in my desktop inside the folder i have saved the Excel file.In my programming during run time when i clicked the upload a folder the excel file should automaticclay saved the excel file datas into database.

Regards
Balamurugan
Posted
Comments
OriginalGriff 24-Nov-12 3:15am    
And your problem is?
What have you tried?
Where are you stuck?
Balamurugan1989 24-Nov-12 8:53am    
I have tried to implement from Excel to database.But my Query is When i'm clicking the folder it should retrieve the content of the file which has inside the folder and should display in Database.
Bhushan Shah1988 24-Nov-12 3:31am    
what is your issue??

1 solution

Update Button Click
1. first you need to read data from Excel sheet to DataTable(Using Oledb Provider for Excel)

Connection String for Excel
C#
string Con_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_Path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";";  

2. if you want Comparison between u r Database and Excel Sheet Then

Here Fdt means ExcelDataTable and Adt Means u r SqlDataTable
C#
public DataTable CompareDataTable(DataTable Fdt, DataTable Adt)
      {
          DataTable Cdt = new DataTable(); // Comparison DataTable
          Cdt = Fdt.Clone();
          bool flag = false;
          try
          {
              foreach (DataRow Mrow in Fdt.Rows)
              {
                  var Marray = Mrow.ItemArray;
                  foreach (DataRow Arow in Adt.Rows)
                  {
                      var Aarray = Arow.ItemArray;
                      if (Aarray.SequenceEqual(Marray))
                      {
                          flag = true;
                          break;
                      }
                      else
                      {
                          flag = false;
                      }
                  }
                  if (flag == false)
                  {
                      Cdt.LoadDataRow(Mrow.ItemArray, LoadOption.PreserveChanges);
                  }
              }
          }
          catch (Exception ex)
          {

          }
          return Cdt;
      }

Now u got Comparison Table Then using foreach loop you can Insert Cdt into Sql at run time

I hope this will help you

If any Query pls Comment

[edit]code block added[/edit]
 
Share this answer
 
v2
Comments
Balamurugan1989 24-Nov-12 8:51am    
I'm using Sqlserver for backend.
vishal jodh 26-Nov-12 2:55am    
Above, I am Clearly mention Fdt means ExcelDataTable and Adt Means u r SqlServerDataTable

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