Larry Hojer

Larry Hojer

  • NA
  • 15
  • 0

C# - methods and return value of Boolean type

Jun 12 2007 5:59 AM
Hello !

I'am rather new to C#, but have som programing experience in VBA and VB. I'am learning Visual development in C#.

Problem:

I'am trying to call a method with a string value and to have the called method to return a boolean false value indicating that a lookup in the database returned a value that allready exists. I recieve an error that says: not all code paths return a value. Thanks in advance,

Here's the code:

chkFrm(ddlCompany.Text);

public Boolean chkFrm(string searchParam)

{

string ddlComp = "'" + searchParam + "%" + "'";

string sql = @"SELECT Name FROM Company WHERE Name LIKE " + ddlComp;

SqlConnection con = new SqlConnection(

"data source=.;initial catalog=survSys;" +

"user id=laho;pwd=12345");

SqlCommand cmd = new SqlCommand(sql, con);

con.Open();

string name = null;

try

{

name = (string)cmd.ExecuteScalar();

if (name != null)

{

return false;

}

}

finally

{

con.Close();

}

}



Answers (4)