title: How to save uploaded .csv file into SQL Server Management database using asp.net
body: <p>This is a sample of my code. I am using Microsoft Visual Studio 2010, with asp.net version 2.0, when the user clicks the import button, the csv file will be saved in the database. My code contains errors, and I do not know how to solve them, please help!</p>
  
  <pre><code>protected void btnImport_Click(object sender, EventArgs e)
  {
      SqlConnection con = new SqlConnection (@"Data Source=localhost\SQLEXPRESS;Initial Catalog=PSeminar;Integrated Security=true;Trusted_Connection=Yes;MultipleActiveResultSets=true");
      StreamReader Sr = new StreamReader("filepath");
  
      string line;
      while ((line = Sr.ReadLine()) != null)
      {
          line = Sr.ReadLine();
      }
  
      const string SQL = "INSERT INTO [Guest] ([GuestName], [IC_Number], [EventName], [GuestID]) VALUES (@GuestName, @IC_Number, @EventName, @GuestID)";
      SqlCommand cmd = new SqlCommand(SQL, con);
      cmd.Parameters.AddWithValue("@GuestName", Sr);
      cmd.Parameters.AddWithValue("@IC_Number", Sr);
      cmd.Parameters.AddWithValue("@EventName", Sr);
      cmd.Parameters.AddWithValue("@GuestID", Sr);
  
      con.Open();
      cmd.ExecuteNonQuery();// 1,0 will determine whether line is inserted, upload has error...
      con.Close();
  }
  </code></pre>