Problema com método
Bom gente, sou muito iniciante em C#, portanto criei uma classe bem básica que tem uma propriedade que retorna um valor a partir de um método (gente, não tenho idéia se o que estou fazendo está correto, estou iniciando em OO):Aqui está a classe:
using System;using System.Data.SqlClient; namespace prjCadCSharp{ /// <summary> /// Summary description for clsCliente2. /// </summary> /// public class clsCliente { string nomeCliente; //SqlClient public clsCliente() { // Constructor } public string NomeCliente { get { return CarregarLista(); } } public string CarregarLista() // AQUI ESTÁ SENDO GERADO O ERRO { SqlConnection oConnection = new SqlConnection(); SqlCommand oCommand = new SqlCommand(); oConnection.ConnectionString = "Initial Catalog= testeCSharp;User ID=sa;Password=sa;DATA Source=DEV1"; oCommand.Connection = oConnection; oCommand.CommandText = "Select * From Clientes"; oConnection.Open(); SqlDataReader myReader; myReader = oCommand.ExecuteReader(); try { while(myReader.Read()) { //Console.WriteLine(myReader.GetString(0)); return myReader.GetValue(1).ToString(); //pictureBox1.Image = Convert.ChangeType(myReader.GetSqlBinary(4), System.Drawing.Image); } } catch { return (""); } finally { myReader.Close(); oConnection.Close(); } } }}Aonde está escrito "AQUI ESTÁ SENDO GERADO O ERRO" me retorna o seguinte:
> not all code paths return a value
Bom gente, se conseguirem me ajudar seria ótimo, fico muito agradecido. Grande abraço a todos.Wai,Rafael Portal
Discussão (1)
Carregando comentários...