Problema l'accesso a un database MySQL su ODBC
Domanda
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);
}
I rendimenti dei server No data exists for the row/column.
La mia tabella del database è strutturato in questo modo (screencap da phpMyAdmin) http://1.img.anyhub.net/1243660397_6485910f8b3fc9ee3e2d93831ad554fd.png
A proposito, dbc
è solo una classe di connessione al database di mine; la funzione Query()
è questa:
public OdbcDataReader Query(string QueryStr)
{
OdbcCommand q = new OdbcCommand(QueryStr, conn);
OdbcDataReader r = q.ExecuteReader();
return r;
}
Soluzione
Credo che si dovrebbe utilizzare il metodo DataReader.Read prima di poter ottenere i dati da esso.
q.Read();
this.Author = q.GetString(6);
E mi consiglia di utilizzare un blocco utilizzando con voi DataReader e oggetti comando
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow