0

I'm just reading values from SQLite tables and storing them into lists. So far I've been able to do this successfully with every column, most columns just have numbers of regular format in them; i.e just plain numbers without any other characters.

Problem:

When I try to read the YYYY-MM Column, it doesn't work as my yymm list just doesn't get populated. I think its because the numbers (note they are set as text in the database) in the YYYY-MM column have a "-" sign in there.

Here's a view of the actual YYYY-MM column in my datagridview (note over here everything in the table is text datatype although they are numbers)

enter image description here

So what am I doing wrong?

string sql6 = "select YYMM, TotalTrans from t2 where CAST(TotalTrans as Real) < 1000.00";
SQLiteCommand command3 = new SQLiteCommand(sql6, sqlite_conn);


SQLiteDataReader reader3 = command3.ExecuteReader();

while (reader3.Read())
{
    int yyyymm;
    double TotalTrans;
    if (int.TryParse(reader3["YYMM"].ToString(), out yyyymm) && double.TryParse(reader3["TotalTrans"].ToString(), out TotalTrans) )
    {
        YYMM.Add(yyyymm);
        TotalTransIrregularities.Add(TotalTrans);
    }
}
1
  • What data type is the YYMM column? Why are you converting it to a string then the string to an integer? Neither of those are dates. Commented Nov 19, 2013 at 0:59

1 Answer 1

1

you need to use DateTime.TryParse() not int.TryParse()

Try This:

DateTime yyyymm;
if(DateTime.TryParse(reader3["YYMM"].ToString(),out yyyymm) && double.TryParse(reader3["TotalTrans"].ToString(), out TotalTrans) )
{    
  YYMM.Add(yyyymm.ToString("yyyy")+"-"+yyyymm.ToString("MM"));
  TotalTransIrregularities.Add(TotalTrans);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.