1
Facebook is a class where I store user information, but I don’t know how I use the ExecuteReader
to get the information.
Can anyone help me with this? (I’m new to the language c#)
public Usuario buscarUsuario(int id){
Usuario usuario = new Usuario ();
string sql = "SELECT * FROM usuario WHERE id = " + id;
try{
Csql = new ConectSQL();
MySqlCommand cmd;
cmd = new MySqlCommand();
cmd.Connection = Csql.OpenBanco();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
MySqlDataReader rdr;
rdr = cmd.ExecuteReader();
if(rdr.HasRows)
while(rdr.Read()){
usuario.Id = rdr.GetInt32(0);
usuario.Nick = rdr.GetString(1);
usuario.Cadastro = rdr.GetString(2);
usuario.Tipo = rdr.GetInt32(3);
usuario.Facebook = rdr.GetString(4); //eu não set q get usar.
}
Csql.CloseBanco();
return usuario;
}
this is the error that is appearing.
Assets/DAO/Usuariodao.Cs(52,49): error CS0029: Cannot implicitly Convert type `string' to `Facebook'
Facebook
is a class, right? You have to do another select to get the information from it. By the way, what is the content of this column of index 4?– Jéf Bueno
Can you post your User and Facebook class, ? and how your Facebook class data is stored in the database?
– Marco Souza
Post the Facebook class too so we can see!
– Leonardo Nascimento Cintra