Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Answers
C# - methods and return value of Boolean type
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Larry Hojer
17y
2.2k
1
Reply
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();
}
}
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
Formatting text that has been read from text file?
how to destroy a form with it`s hide