Exemplo n.º 1
0
    public static Moto_Model GetMotorista(int codigo)
    {
        SqlConnection con = new SqlConnection(AcessoDB.ConnectionString);

        try
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("getMotorista", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@codigo", codigo);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Moto_Model ct = new Moto_Model();
                ct.Cpf   = dr["cpf"].ToString();
                ct.Nome  = dr["nome"].ToString();
                ct.Sexo  = dr["sexo"].ToString();
                ct.Idade = Int32.Parse(dr["idade"].ToString());
                ct.Ativo = dr["ativo"].ToString();
                return(ct);
            }
            else
            {
                return(null);
            }
        }
        catch (Exception ex)
        {
            Serv.Sqlerro = "Error -> " + ex.Message;
            return(null);
        }
        finally
        {
            con.Close();
        }
    }