title: Passing DataSet to Stored Procedure
body: <p>I have the following Stored Procedure that receives a <code>DataSet</code> as parameter and Inserts into table <code>Excel</code>.</p>
  
  <pre><code>CREATE PROCEDURE spInsertInvoice
        @tblInvoice InvoiceType READONLY
  AS
  BEGIN
        SET NOCOUNT ON;
  
        INSERT INTO Excel
        SELECT Template, Cust_Name, Invoice_No,InvoiceDate FROM @tblInvoice
  END
  </code></pre>
  
  <p>In my code file I am trying to read the <code>Excel Sheet</code> and filling the dataset. But problem is I am a bit confused as to how should I send the <code>DataSet</code> as <code>Parameter</code> to the <code>stored Procedure</code>.
  This is what I have tried so far, but it doesn't seem to work</p>
  
  <pre><code>if (FileUpload1.HasFile)
          {
              string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));
              FileUpload1.PostedFile.SaveAs(path);
              OleDbConnection oleCon = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties = Excel 12.0;");
              OleDbCommand Olecmd = new OleDbCommand("select * from [Sheet1$]", oleCon);
              OleDbDataAdapter dtap = new OleDbDataAdapter(Olecmd);
              DataSet ds = new DataSet();
              dtap.Fill(ds);
              GridView1.DataSource = ds;
              GridView1.DataBind();
              if (ds.Tables[0].Rows.Count &gt; 0)
              {
                  string consString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
                  using (SqlConnection con = new SqlConnection(consString))
                  {
                      using (SqlCommand cmd = new SqlCommand("spInsertInvoice"))
                      {
                          cmd.CommandType = CommandType.StoredProcedure;
                          cmd.Connection = con;
                          cmd.Parameters.AddWithValue("@tblInvoice", ds);
                          con.Open();
                          cmd.ExecuteNonQuery();
                          con.Close();
                      }
                  }
              }
  </code></pre>
  
  <p>When I execute it, it throws <code>ArgumentException</code> on <code>cmd.ExecuteNonQuery()</code></p>
  
  <blockquote>
    <p>No mapping exists from object type System.Data.DataSet to a known
    managed provider native type.</p>
  </blockquote>