Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

C# casting question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WebBuilder451 - 27 Aug 2007 17:40 GMT
I know this one is basic (and Thanks)
i have a  function that calls a storedprocedure and i'm using the return
code for validation See Below

   public Boolean fn_isVaildUser(string userid, string password)
   {
       // returns 0 invalid or 1 valid for a userid and password
       string constr =
ConfigurationManager.ConnectionStrings["arlcapConnectionString"].ConnectionString;
       SqlConnection sqlcon1 = new SqlConnection(constr);
       SqlCommand sqlcmd1 = sqlcon1.CreateCommand();
       sqlcmd1.CommandType = CommandType.StoredProcedure;
       sqlcmd1.CommandText = "sp_GetUserLogin";
       sqlcmd1.Parameters.AddWithValue("@szUserid", userid);
       sqlcmd1.Parameters.AddWithValue("@szPassword", password);
       SqlParameter isOK = sqlcmd1.Parameters.Add("@isOK", null);
       isOK.SqlDbType = SqlDbType.Int;
       isOK.Direction = ParameterDirection.ReturnValue;
       sqlcon1.Open();
       sqlcmd1.ExecuteNonQuery();
       sqlcon1.Close();
       sqlcmd1.Dispose();
       sqlcon1 = null;
       sqlcmd1 = null;
       if ((Int32)isOK.Value == 0)
           return false;
       else
           return true;
      /// return (Boolean)isOK.Value;
   }
The question has to do with the last commented out line.
I want to just want t ocast and return the "isOK.Value but i keep getting
errors.
ERROR: "Specified cast is not valid."
(It does work as is, but i'd perfer to do it what i consider correctly.)
Signature

thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes

Sherif Elmetainy - 27 Aug 2007 18:02 GMT
Your parameter type should be bit so that you can cast it to Boolean.
Otherwise you can use Convert.ToBoolean(isOK.Value)

Regards,
Sherif

>I know this one is basic (and Thanks)
> i have a  function that calls a storedprocedure and i'm using the return
[quoted text clipped - 31 lines]
> ERROR: "Specified cast is not valid."
> (It does work as is, but i'd perfer to do it what i consider correctly.)
WebBuilder451 - 27 Aug 2007 19:12 GMT
Thank you,
I'm still getting used to C#, but i think in this case is was an issue of
missing the obvious!
Signature

thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes

> Your parameter type should be bit so that you can cast it to Boolean.
> Otherwise you can use Convert.ToBoolean(isOK.Value)
[quoted text clipped - 37 lines]
> > ERROR: "Specified cast is not valid."
> > (It does work as is, but i'd perfer to do it what i consider correctly.)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.