user3187867
user3187867

Reputation: 61

Input String was not in the correct format error c#

I am inserting values from a database into a chart.. I am pulling the data from 2 columns, the first column contains String values ( Mixture of letters, numbers and spaces) and the second column contains float values (Just numeric types) . When ever I run the query I keep getting this error: "Input String was not in the correct format" Can some one help me pls?

try { 
    Query = "SELECT * FROM Products;";
    Reader = conn.ExecuteStatement(Query);

    while (Reader.Read()) { 
        this.chart1.Series["Series1"].Points.
        AddXY((Double.Parse(Regex.Replace(Reader.GetString(1),@"[^\d|\.]",""))),
        (Convert.ToDouble(Reader.GetInt32(4))));
    }
}
catch (Exception ex) {
    MessageBox.Show(ex.Message); 
}

conn.CloseConnection();

Upvotes: 0

Views: 670

Answers (1)

Roland Mai
Roland Mai

Reputation: 31097

This is a data issue. Either Reader.GetString(1) or Reader.GetString(4) is returning something that cannot be parsed or converted to double.

Instead of relying on SELECT * FROM Products, list the column names and be sure to select from the proper columns.

Upvotes: 2

Related Questions