Hi All: Uisng SQLiteDataReader i'm getting the table values but i'm not getting the column value using SQLiteDataReader GetName
My goal is to i want data with column name in excel file which is same as query then followed by the table values. wWhat is the mistake here? thanks
I think i'm making mistake in the for loop?
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = xlWorkBook.Worksheets[1]; // (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Name = "Stats";
string cs = @"C:\\db_test\\Database.db";
string data = String.Empty;
int i = 0;
int j = 0;
using (SQLiteConnection con = new SQLiteConnection("Data Source=C:\\db_test\\Database.db"))
{
con.Open();
//string stm = "SELECT Oid from Stats";
StringBuilder query = new StringBuilder();
query.Append("SELECT");
query.Append("[Oid], [CreatedOn], [OrderOid] ");
query.Append(",[OrderLineOid], [OrderNumber], [Product] ");
query.Append(",[PaperTypeName], [OutputProfile], [OutputProfileChannel] ");
query.Append("FROM Stats");
using (SQLiteCommand cmd = new SQLiteCommand(query.ToString(), con))
{
using (SQLiteDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read()) // Reading Rows
{
var columns = new List<string>();
for (j = 0; j <= rdr.FieldCount - 1; j++) // Looping throw colums
{
columns.Add(rdr.GetName(j));
data = rdr.GetValue(j).ToString();
xlWorkSheet.Cells[i + 1, j + 1] = data;
}
i++;
}
}
}
con.Close();
}
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +"\\"+ "Statictics_" + DateTime.Now.ToString("yyyyMMdd") + ".xls";
xlWorkBook.SaveAs(path, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
columnsbut you're not using them anymore. You're just writingdata-which only contains the values- to your Excel file.