Receiving Database Search with SQL Reader

1

Facebook is a class where I store user information, but I do not know how to use ExecuteReader to get the information.

Can anyone help me with this? (I'm new to C # language)

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 / UserID.cs (52,49): error CS0029: Can not implicitly convert type 'string' to 'FaceBook'

    
asked by anonymous 10.03.2016 / 10:55

1 answer

0

facebook class:

using UnityEngine;
using System.Collections;

public class FaceBook : MonoBehaviour {
    private int id;
    private string first;
    private string last;
    private string email;
    private byte[] foto;
    private string page_id;
    private string aniversario;

    public FaceBook(){

    }

    public FaceBook(int id, string fisrt, string last, string email, byte[] foto, string page_id, string aniversario){
        this.id = id;
        this.first = first;
        this.last = last;
        this.email = email;
        this.foto = foto;
        this.page_id = page_id;
        this.aniversario = aniversario;
    }

    public int Id{
        get{
            return id;
        }
        set{
            id = value;
        }
    }

    public string First {
        get {
            return first;
        }
        set {
            first = value;
        }
    }

    public string Last {
        get {
            return last;
        }
        set {
            last = value;
        }
    }

    public string Email {
        get {
            return email;
        }
        set {
            email = value;
        }
    }

    public byte[] Foto{
        get{
            return foto;
        }
        set{
            foto = value;
        }
    }

    public string Page_id{
        get{
            return page_id;
        }
        set{
            page_id = value;
        }
    }

    public string Aniversario{
        get{
            return aniversario;
        }
        set{
            aniversario = value;
        }
    }
}
    
11.03.2016 / 23:57