title: read column names from sqlite table windows 8 app
body: <p>I am using SQLite for a data entry windows 8 app I am working on.  I can create the db, insert data, retrieve a column count, and read data, but cannot get the column names.</p>
  
  <p>The underlying framework is from this <a href="http://wp.qmatteoq.com/using-sqlite-in-your-windows-8-metro-style-applications/" rel="nofollow">post</a>.</p>
  
  <p>I read about the <code>PRAGMA table_info(table_name);</code> command but I cannot seem to send and read back this query properly.  I have been googling for 3 days!</p>
  
  <p>MainPage.xaml.cs:</p>
  
  <pre><code>using SQLite;
  using SqlLiteTest.Model;
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Linq;
  using Windows.Storage;
  using Windows.UI.Popups;
  using Windows.UI.Xaml;
  using Windows.UI.Xaml.Controls;
  
  namespace SqlLiteTest
  {
      public sealed partial class MainPage : Page
      {
          public MainPage()
          {
              this.InitializeComponent();
              txtPath.Text = ApplicationData.Current.LocalFolder.Path;
          }
  
          private async void createDB(object sender, RoutedEventArgs e)
          {
              // access local folder
              var qvLocalFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
  
              try
              {
                  //Create a blank carrier file
                  StorageFile qvLocalFileCarrier = await qvLocalFolder.CreateFileAsync("qvdbLocal.db", CreationCollisionOption.FailIfExists);
  
                  //Write the blank carrier file
                  await FileIO.WriteTextAsync(qvLocalFileCarrier, "");
              }
              catch { }
  
              // connect
              var path = Windows.Storage.ApplicationData.Current.LocalFolder.Path + @"\qvdbLocal.db";
              var db = new SQLiteAsyncConnection(path);
  
              // create table
              await db.CreateTableAsync&lt;qvdb&gt;();
  
              // insert data
              var insertRecords = new List&lt;qvdb&gt;()
              {
                  new qvdb
                  {
                              qvdbRecord = 1,
                              qvdbNotes = "Notes1",
                              qvdb001 = "Variable 1.1",
                              qvdb002  = "Variable 2.1"
                      },
                      new qvdb
                      {
                              qvdbRecord = 1,
                              qvdbNotes = "Notes1",
                              qvdb001 = "Variable 1.1",
                              qvdb002  = "Variable 2.1"
                      },
                      new qvdb
                      {
                              qvdbRecord = 1,
                              qvdbNotes = "Notes1",
                              qvdb001 = "Variable 1.1",
                              qvdb002  = "Variable 2.1"
                      },
              };
  
              await db.InsertAllAsync(insertRecords);
  
              // read count
              var allUsers = await db.QueryAsync&lt;qvdb&gt;("SELECT * FROM qvdb");
              var count = allUsers.Any() ? allUsers.Count : 0;
  
              Debug.WriteLine(count);
          }
  
          private async void updateDB(object sender, RoutedEventArgs e)
          {
              var path = Windows.Storage.ApplicationData.Current.LocalFolder.Path + @"\qvdbLocal.db";
              var db = new SQLiteAsyncConnection(path);
  
              var tempCell = db.QueryAsync&lt;qvdb&gt;("UPDATE qvdb SET qvdbNotes ='!@#$%$%^^&amp;*()+)(*&amp;^%$#@!{:L&lt;&gt;?' WHERE qvdbRecord = 10");
              await db.UpdateAsync(tempCell);
          }
  
          private async void readDB(object sender, RoutedEventArgs e)
          {
              var path = Windows.Storage.ApplicationData.Current.LocalFolder.Path + @"\qvdbLocal.db";
              var db = new SQLiteAsyncConnection(path);
  
              var query = db.Table&lt;qvdb&gt;();
              var result = await query.ToListAsync();
              foreach (var item in result)
              {
                  MessageDialog dialog = new MessageDialog(string.Format("{0} {1} {2}", item.qvdbRecord, item.qvdbNotes, item.qvdb001));
                  await dialog.ShowAsync();
              }
          }
  
          private void readColNames(object sender, RoutedEventArgs e)
          {
          }
      }
  }
  </code></pre>
  
  <p>qvdb.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using SQLite;
  
  namespace SqlLiteTest.Model
  {
      public class qvdb
      {
          [PrimaryKey, AutoIncrement]
          public int qvdbRecord { get; set; }
  
          [MaxLength(3000)]
          public string qvdbNotes { get; set; }
  
          [MaxLength(1000)]
          public string qvdb001 { get; set; }
  
          [MaxLength(1000)]
          public string qvdb002 { get; set; }
  
      }
  }
  </code></pre>
  
  <p>Thanks CL for the info.  I added the class but still do not know how to access them.  Some more code...</p>
  
  <pre><code>    // this works
      // read record count
      var allRecords = await db.QueryAsync&lt;qvdb&gt;("SELECT * FROM qvdb");
      var countRecords = allRecords.Any() ? allRecords.Count : 0;
      this.textboxLog.Text = this.textboxLog.Text + Environment.NewLine + "There are " + countRecords + " records.";
  
      // ??
      // read column names
      var allColumns = await db.QueryAsync&lt;qvdb&gt;("PRAGMA table_info(qvdb)");
      foreach (var item in allColumns) {
         //read name
          this.textboxLog.Text = this.textboxLog.Text + Environment.NewLine + "columbn names";
      }
  </code></pre>