You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to add data to a table in a SQLite database by getting data from a excel file using the fastexcel library.
But I cannot figure out how do I get values from specific cells/column of a row in a worksheet.
public void UpdateDBtable()
{
DataTable dt = new DataTable();
dt.Columns.Add("Party");
dt.Columns.Add("Bill No");
...
dt.Columns.Add("Head");
string file_Bills = @"D:\Test\Test.xlsx";
using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(file_Bills, true))
{
Worksheet worksheet = fastExcel.Read(1);
var rows = worksheet.Rows.ToArray();
//ideally the below rows.Count() should be the count of number of rows whose column A value exists but don't know how to do that either
for (int _row = 2; _row <= rows.Count(); _row++)
{
DataRow dr = dt.NewRow();
//below line is intended to get specific cells text but doesn't work
dt.Rows.Add(worksheet.Cells[_row, 1].Text, worksheet.Cells[_row, 2].Text, ..., worksheet.Cells[_row, 7].Text);
dt.AcceptChanges();
}
using(SQLiteConnection conn= new SQLiteConnection(@"Data Source="+Path.GetFullPath("./test.db")))
{
conn.Open();
using (var cmd = new SQLiteCommand(conn))
{
string str;
SQLiteCommand com;
foreach (DataRow row in dt.Rows)
{
str = "INSERT OR IGNORE INTO billdata(Party,BillNo,...,Head)values(@Party,@BillNo,...,@Head)";
com = new SQLiteCommand(str, conn);
com.Parameters.AddWithValue("@Party", row.Field<string>(0));
com.Parameters.AddWithValue("@BillNo", row.Field<string>(1));
...
com.Parameters.AddWithValue("@Head", row.Field<string>(8));
com.ExecuteNonQuery();
}
}
conn.Close();
}
}
}
The text was updated successfully, but these errors were encountered:
I'm trying to add data to a table in a SQLite database by getting data from a excel file using the fastexcel library.
But I cannot figure out how do I get values from specific cells/column of a row in a worksheet.
The text was updated successfully, but these errors were encountered: