TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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();
}
}
Reply
Answers (
4
)
Formatting text that has been read from text file?
How to show a tab control on the left side of the form in vb.net 2003