I'm using c#, winforms, SQlite as my database.
I'm running the following query:
string sql14 = "select YYMM, TotalTrans from t2 where CAST(TotalTrans as int) < 500000 and CAST(TotalTrans as int) > 1000";
I then use this query to populate 2 lists, which I then export to a menustrip where the user can select it like this:
string sql14 = "select YYMM, TotalTrans from t2 where CAST(TotalTrans as int) < 500000 and CAST(TotalTrans as int) > 1000";
SQLiteCommand cmd5 = new SQLiteCommand(sql14, sqlite_conn);
SQLiteDataReader rdr5 = cmd5.ExecuteReader();
while (rdr5.Read())
{
int TotalTranst22;
DateTime yyyymmt22;
if (DateTime.TryParse(rdr5["YYMM"].ToString(), out yyyymmt22) && int.TryParse(rdr5["TotalTrans"].ToString(), out TotalTranst22))
{
// Populating the lists
YYMMt22.Add(yyyymmt22);
TotalTransIrregularitiest22.Add(TotalTranst22);
}
}
Problem: When I select the option to show the contents of the 2 lists YMMt22 and TotalTransIrrefularitiest22, nothing happens. While trying to debug I found out that the lists are completely empty, i.e: the query isn't working.
Update:
The problem arises when I try to run the query for values > 1000, as they have a ',' in them.
Also, when trying a user suggestion (below)
SELECT CAST(TotalTrans as int) FROM t2`
I get an error saying the index was out of bounds of array in the condition of my if statement
Here is the actual data I'm trying to store in the lists via the query. As you can see, it does have thousands separators (the commas).
Just for the record: I know this process of querying my table works because I used a similar query to get values <1000 (notice they dont have a ',') and it worked perfectly. Here's the code for that:
// Total Trans tolerance <1000
string sql13 = "select YYMM, TotalTrans from t2 where cast(TotalTrans as int) < 1000";
Update:
Tried a user solution... still no luck. The lists dont get filled with any data
string sql14 = "select YYMM, TotalTrans from t2 where CAST(REPLACE(TotalTrans, ',', '') as int) < 500000 and CAST(REPLACE(TotalTrans, ',', '') as int) > 1000";
SQLiteCommand cmd5 = new SQLiteCommand(sql14, sqlite_conn);
SQLiteDataReader rdr5 = cmd5.ExecuteReader();
while (rdr5.Read())
{
int TotalTranst22;
DateTime yyyymmt22;
if (DateTime.TryParse(rdr5["YYMM"].ToString(), out yyyymmt22) && int.TryParse(rdr5["TotalTrans"].ToString(), out TotalTranst22))
{
YYMMt22.Add(yyyymmt22);
TotalTransIrregularitiest22.Add(TotalTranst22);
}
}