I know there a some other questions related to mine but still they do not help me very much. I tried to understand the concept of the String.Format Method but i failed over and over again and still have no clue how to use it in my case. I know it is asked very much but if someone has an idea how to get the alignment in place i would appreciate it a lot.

I'm saving the output of different database tables to different text files. I want to align the "name" of the column to its "value". This makes very much sense because in some tables there a lot of "null" values and that leads to a poorly formatted output. Because the "null" is not exported to that file and therefore the values are moved to the left.

[![Database Table vs. Text File](https://i.stack.imgur.com/Yc2c0.png)](https://i.stack.imgur.com/Yc2c0.png)

```
private void WriteSQLQueryOutputToTextFile(string DBUser, string DBUserPassword, string sqlQuery, string databaseName, string nameOfOutputFile)
{
    string pathOfOutputFile = dWTestResult + "\\DatabaseUpgradeCheck\\" + nameOfOutputFile;           

    using (SqlConnection sqlCon = new SqlConnection("Data Source=" + 
    GetEnvironmentVariable.MachineName + "; Initial Catalog=" + databaseName + "; User ID=" + DBUser + "; Password=" + DBUserPassword + ";"))
    {
        SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, sqlCon);     
        try
        {
          sqlCon.Open();
          DataSet dataset = new DataSet();
          adapter.Fill(dataset, "nameOfDataset");
          string currentLine = "";
          foreach (var col in dataset.Tables[0].Columns)
          {
            currentLine += " " + col.ToString();
          }

         OutputHandler.AppendDataToFile(pathOfOutputFile, currentLine);

         foreach (DataRow row in dataset.Tables[0].Rows)
         {
            currentLine = "";
            foreach (var item in row.ItemArray)
            {
                currentLine += " " + item.ToString();
            }
            OutputHandler.AppendDataToFile(pathOfOutputFile, currentLine);
          }
     }
     catch (Exception ex)
     {
        logger.Debug(ex, "Writing Database Output to the " + "\"" + nameOfOutputFile + "\"" + " file failed");
     }
     finally
     {
        sqlCon.Close();
     }
   }
}

```