c# - Cannot implicitly convert type bool to string -


i'm trying create check name method see if user exist in database. created check() function/method in class called sqlfunctions2.but have error in code , can't seem fix. appreciate it. :)

using system; using system.collections.generic; using system.linq; using system.text; using system.windows.forms; using system.data.sql; using system.data.sqlclient;  namespace contact_form {    public class sqlfunctions2     {        static private sqlconnection conn = new sqlconnection("my string connection here");         public static string check(string name)        {               try            {                conn.open();                int exist;                /*check see if username in database.*/                sqlcommand exist_cmd = new sqlcommand("select count(*) tbl_contact_form name=@name", conn);                exist_cmd.parameters.addwithvalue("@name", name);                exist = (int)exist_cmd.executescalar();                  if (exist == 1)                {                     sqldatareader myreader = null;                    sqlcommand mycommand = new sqlcommand("select * tbl_contact_form name=@name", conn);                    mycommand.parameters.addwithvalue("@name", name);                    myreader = mycommand.executereader();                    while (myreader.read())                    {                        string result_name = myreader["name"].tostring();                        string result_amount = myreader["amount_borrowed"].tostring();                         return true; /* error in line of code...                                    cannot implicitly convert type 'bool' 'string'*/                    }                }                else if(exist == 0)                {                     return false;                     messagebox.show("no such user.");                }            }            catch (exception ex)            {                messagebox.show(ex.tostring());            }                       {            conn.close();            }         }     } } 

the method check of type string , since returning bool, must change method check to:

public static bool check(string name) 

as can see has type of bool now, , can accept bool return statements.

either that, or if wanting return string saying true or false, must use return "true"; or return "false"; system can identify type.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -