title: Import data from excel to mysql using c#
body: <p>I have Excel file shown bellow</p>
  
  <p><img src="https://i.stack.imgur.com/ufoOk.png" alt="enter image description here"></p>
  
  <p>I want to read 1st read only all school names &amp; school address &amp; insert them in SchoolInfo table of mySql database.</p>
  
  <p>After that I want to read data for each school &amp; insert it in StudentsInfo table which has foreign key associated with SchoolInfo table.</p>
  
  <p>I am reading excel sheet something like this.</p>
  
  <p>public static void Import(string fileName)
      {
          string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName +
                           ";Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\"";</p>
  
  <pre><code>    var output = new DataSet();
  
      using (var conn = new OleDbConnection(strConn))
      {
          conn.Open();
  
          var dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
  
          if (dt != null)
              foreach (DataRow row in dt.Rows)
              {
                  string sheet = row["TABLE_NAME"].ToString();
  
                  var cmd = new OleDbCommand("SELECT * FROM [+"+sheet+"+]", conn);
                  cmd.CommandType = CommandType.Text;
  
                  OleDbDataAdapter xlAdapter = new OleDbDataAdapter(cmd);
  
                  xlAdapter.Fill(output,"School");
              }
      }
  
  }
  </code></pre>
  
  <p>Now I am having data in datatable of dataset, Now how do I read desired data &amp; insert it in my sql table.</p>