TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
L Hazlewood
NA
23
1k
SQLite and Windows 2017 C# query of database file
Mar 15 2018 6:15 AM
In this section of code I select a range of dates to use to get the rows from a SQLite database file "Mytable1 table name "Date". The SELECT command I am using works correctly when using a SQLite database manager program but using C# in a windows form the dates returned are not between the date range requested.
Anyone run into this issue before?
I use a DataView Grid to display the return data and a button to SELECT the table and "Date coloum. A DataBase file (.zip) and a few lines of code I am using.
using
System.Data.SQLite;
//SQL connection, Adaptor and data table
SQLiteConnection myConn;
SQLiteDataAdapter myAdapter;
DataTable myTable;
// Loads page and opens data base
private
void
Reports_Load_1(
object
sender, EventArgs e)
// add event load
{
// check if file exists
if
(File.Exists(Application.StartupPath +
"/mytable1.db3"
))
// change back to mytables when testing is done
{
string
myDbPath = Application.StartupPath +
"/mytable1.db3"
;
// change back to mytables when testing is done
// if DB does not exist, it will create it.
myConn =
new
SQLiteConnection(
"Data Source="
+ myDbPath);
myConn.Open();
// open DB file
}
else
{
MessageBox.Show(
"Data Base not found:"
+ Environment.NewLine +
// addes a new line
" Check file location and name"
);
}
}
private
void
BtnGenerate_Click(
object
sender, EventArgs e)
{
myAdapter =
new
SQLiteDataAdapter (
"SELECT DISTINCT * FROM Transaction_Table WHERE Date >= "
+2018/01/01+
" AND Date <= "
+2018/01/04+
";"
, myConn);
// this works in SQLite database browser. In visualstudio 2015 C# gives all dates regardless of the date rang you change it to.
// myAdapter = new SQLiteDataAdapter("SELECT DISTINCT * FROM Transaction_Table WHERE date BETWEEN " + 2018/01/01 + " AND " + 2018/01/04 + ";", myConn); // this also gets all dates
myTable =
new
DataTable();
// myReport = new DataTable(); // Don't forget initialize!
myAdapter.Fill(myTable);
// once you get the data
// try this change
// bindingSource1.DataSource = myTable;
// SQLiteCommandBuilder authomatically generates
// neccessary INSERT, UPDATE, DELETE SQL queries.
new
SQLiteCommandBuilder(myAdapter);
// ----------- Binding DataTable To DataGridView -----------
// ---------------------------------------------------------
// DataGridView visualizes DataTable's data in the window.
// ! THIS CODE IS REQUIRED (if we want DataGridView)
DataGridView1.DataSource = myTable;
}
Attachment:
mytable1.zip
Reply
Answers (
2
)
While converting XML to JSON using c#
barcode reader generating and reading values