views:

91

answers:

1
OdbcDataReader q = dbc.Query("SELECT * FROM `posts` WHERE `id`=" + id.ToString());
if (q.RecordsAffected < 1)
{
    this.Exists = false;
}
else
{
    this.Exists = true;
    this.Author = q.GetString(6);
}

The server returns No data exists for the row/column.

My database table is structured like this (screencap from phpMyAdmin)

By the way, dbc is just a database connection class of mine; the Query() function is this:

public OdbcDataReader Query(string QueryStr)
{
    OdbcCommand q = new OdbcCommand(QueryStr, conn);
    OdbcDataReader r = q.ExecuteReader();
    return r;
}
+1  A: 

I think you should use DataReader.Read method before you can get data from it.

q.Read(); 
this.Author = q.GetString(6);

And I recommend using a using block with you DataReader and Command objects

Beatles1692
Jesus... How the hell did I manage to miss the Read()? I also have that all in blocks, but I just copy/pasted the relevant bits.
Charlie Somerville
I feel pretty embarrassed now.
Charlie Somerville