Add in BD in C # [closed]

-2

I'm doing a little project in my college and started messing with C # classes, but I'm having problems inserting (my amount of values in insert does not match values) in my DB and I'm not understanding. my User class:

    private int _codigo;
    private string _senha, _username;
    private byte[] _vetorImagens;

    public int Codigo
    {
        get
        {
            return _codigo;
        }

        set
        {
            _codigo = value;
        }
    }

    public string Senha
    {
        get
        {
            return _senha;
        }

        set
        {
            _senha = value;
        }
    }

    public string Username
    {
        get
        {
            return _username;
        }

        set
        {
            _username = value;
        }
    }

    public byte[] VetorImagens
    {
        get
        {
            return _vetorImagens;
        }

        set
        {
            _vetorImagens = value;
        }
    }

    public string Inserir()
    {


        return "insert into Usuario(Username,Senha,Foto) values ('" + _username+ "''" + _senha + "''" + _vetorImagens +"')";
    }
}

}

    
asked by anonymous 14.11.2016 / 18:08

1 answer

-1

You're missing some commas in the syntax of your Insert.

I would in this case do it this way for better visualization of the assembly of the Insert:

string sql = "",
        sqlInsert = "",
        sqlValues = "";

sqlInsert += " INSERT INTO usuario(";
sqlInsert += "        Username ";
sqlInsert += "       ,Senha";
sqlInsert += "       ,Foto)";

sqlValues += " Values(";
sqlValues += "'" + _username + "',";
sqlValues += "'" + _senha + "',";
sqlValues += "'" + _vetorImagens + "')";


sql = sqlInsert + sqlValues;

return sql;
    
14.11.2016 / 18:11