title: Import Data from .csv to SQL Server using File Upload in Asp.net C#
body: <p>I have an .csv file which I upload it through a <code>FileUpload</code> control and I want to transfer the whole data from that csv file into a SQL Server database table, but I have some problems in my code:</p>
  
  <pre><code> DataTable tblReadCSV = new DataTable();
      tblReadCSV.Columns.Add("EmailId");
      string path = System.IO.Path.GetFileName(fupEmails.PostedFile.FileName);
      fupEmails.PostedFile.SaveAs(Server.MapPath("~/Contacts/" + path));
      path = Server.MapPath("~/Contacts/" + path);
      TextFieldParser csvParser = new TextFieldParser(path);
      csvParser.Delimiters = new string[] { "," };
      csvParser.TrimWhiteSpace = true;
      //csvParser.ReadLine();
      while (!csvParser.EndOfData)
      {
          string[] fields = csvParser.ReadFields();
          tblReadCSV.Rows.Add(fields.Equals("Email"));
      }
      string connection = @"Data Source=ANURAG-PC; Initial Catalog=MailServer; Persist Security Info=True; User ID=sa; Password=anurag";
      string strSql = "Insert into EmailData(EmailId) Values(@Email)";
      SqlConnection con=new SqlConnection(connection);
      SqlCommand cmd=new SqlCommand();
      cmd.CommandType=CommandType.Text;
      cmd.CommandText=strSql;
      cmd.Connection=con;
      cmd.Parameters.Add("@Email",SqlDbType.NVarChar,250,"Email");
      SqlDataAdapter daAdapter=new SqlDataAdapter();
      daAdapter.InsertCommand=cmd;
      int result=daAdapter.Update(tblReadCSV);
      lblError.Text="Send Successfully";
  </code></pre>
  
  <p>and I'm getting error in the second last line</p>
  
  <pre><code>int result = daAdapter.Update(tblReadCSV);
  </code></pre>
  
  <p>and the error is </p>
  
  <blockquote>
    <p>The parameterized query '(@Email nvarchar(250))Insert into EmailData(EmailId) Values(@Ema' expects the parameter '@Email', which was not supplied.</p>
  </blockquote>