title: dynamically select range of cells in excel sheet in C#.Net
body: <p>i am preparing myself for importing data from excel sheet to sql server 2005.I have few requirements while i import data from excel sheet to database.I have searched a lot but i am unable to find the answer and also i am getting confused,so thought of asking my query over here.The excel sheet format is in this way.<br/><br/>
       First row contains Heading "Transaction"<br/>
      Second row contains SubHeading "Date"<br/>
      From third row the data starts with column names followed by the data in resp.rows.<br/></p>
  
  <pre><code>CustId CustName OUtlet TerminalNum   Date     DateTime               Amount&lt;br/&gt;
     1    Nazima   SS     770012234  1/22/2011   1/22/2011 12:34:45    1500.50&lt;br/&gt;
  </code></pre>
  
  <p>this is the way the data is in excel sheet.</p>
  
  <p>i have tried to upload the image but it was showing problem while posting the question.so i typed it.</p>
  
  <p>My requirement is that when i import data from excel sheet to database i have to ignore the first two rows and have to import data from third row and i have to import totalamount(62854) and total no.of rows(11) in one table and data in other table.</p>
  
  <p>I am able to import the data using oledbcommand by using this statement:</p>
  
  <p><code>oledbcommand cmd=new oledbcommand("select * from [sheet1$]",con);</code> and</p>
  
  <pre><code>oledbcomaand cmd=new oledbcommand("select * from [sheet1$A3:H13]",con);
  </code></pre>
  
  <p>these two statements are working but i dont want it in this way because enduser can enter the data from any cell,so i want to dynamically specify the sheet along with range.In whichever cell the enduser start entering data,the data along with total amount and no.of rows should get imported to reso.tables in database without any problem.</p>
  
  <p>And also i want to know how can i insert a new row in table whenever the end user enters a new row in excel sheet without inserting the previous rows which are already present in table.</p>
  
  <p>Next i want to know which is the best way to import data from excel to database.Is it thru excel interop or thru Oledb.I have tried using import/export wizard,SSIS,they are working but i have to do it programatically.</p>
  
  <p>Give me few guidelines how do i need to carry out these process.</p>
  
  <p>Hope u understood my doubt.</p>
  
  <p><a href="https://i.stack.imgur.com/E6pfO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E6pfO.png" alt="enter image description here"></a></p>