c# Input string was in incorrect format error when data reading

253 views Asked by At

so this is my problem.

this function:

    public int Reader(string query, string value, int id, int reader)
    {
        CloseConnection();
        int i = 0;
        con.Open();
        MySqlCommand cmd;
        cmd = new MySqlCommand(query, con);
        cmd.Parameters.AddWithValue(value, id);
        cmd.ExecuteNonQuery();
        MySqlDataReader sdr = cmd.ExecuteReader();
        if (sdr.Read())
        {
            i = sdr.GetInt16(reader);
            con.Close();
        }
        return i;
    }

is supposed to data read mysql command and it works, excpet for this line:

 string str = Convert.ToString(mysqlquery.Reader("SELECT * FROM items WHERE id=@id", "@id", i, 2));

the other lines look exact the same, and only this one doesn't work.

This is how my database looks.

EDIT

replacing the 2 in the en of the line is oke

example:

  string str = Convert.ToString(mysqlquery.Reader("SELECT * FROM items WHERE id=@id", "@id", i, 1));
1

There are 1 answers

0
Demian Berisford-Maynard On BEST ANSWER

Its a complex object, probably an array of sorts. Try accessing the index of the array, then doing the conversion to string.