title: Insert text file data into SQL Server database table of specific column
body: <p>I have attached my code in which I tried to read a <code>.txt</code> file with many records. </p>
  
  <p>The same text file data I need to insert into the SQL Server database table in specific columns. Here is the code I wrote by taking reference from some where. </p>
  
  <pre><code>protected void BtnUpload_Click(object sender, EventArgs e)
  {
      FileUpload(x);
  }
  
  private void FileUpload(List&lt;string&gt; x)
  {       
      SqlConnection con = new SqlConnection(conStr);
      SqlCommand cmd = new SqlCommand();
  
      string fileName = Path.Combine(@"C:\Users\user\Desktop\SBS", FileUpload1.FileName);        
  
      if(FileUpload1.HasFile)
      {
          try
          {
              con.Open();
              List&lt;string&gt; x;
  
              for (int i = 0; i &lt;= x.Count - 9; i += 9)
              {
                  SqlCommand myCommand = new SqlCommand("INSERT INTO SBSFile (SBSBranchCode, BranchName, FinYear, BrChallanNo, TransDate, MajorHead, ReceiptPayment, Amount, PlanNonPlan) " +
                             string.Format("Values('{0}', '{1}',  '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}')", x[i], x[i + 1], x[i + 2], x[i + 3], x[i + 4], x[i + 5], x[i + 6], x[i + 7], x[i + 8], x[i + 9]), con);
                  myCommand.ExecuteNonQuery();
           }
           catch (Exception ex)
           {
           }
       }
   }
  </code></pre>
  
  <p>example of my file :</p>
  
  <blockquote>
    <p>1 |abc| |bcd| |101|</p>
  </blockquote>
  
  <p>here <code>|</code> denoted separator of column and yes every line should be inserted in the table where in specific column is available </p>
  
  <p>Can anyone help me to insert file data into the SQL Server table? </p>
  
  <p>Please help me to solve the issue</p>