-
April 7th, 2004, 08:31 AM
#1
Please help about sqlparameter
i am using sql parameters for authenticat login and password but the porble is here an error ocurs "Specific casting not valid"
see the code
public bool Authenticate(string user, string pass)
{
bool authenticated = false;
SqlConnection myconnection = new SqlConnection();
myconnection.ConnectionString = "Persist Security Info=False;User Id = pcms;Password = pcms;Database=ImportPCMS;Data Source = Vilas;";
myconnection.Open();
SqlCommand cmd = new SqlCommand("Select Username,Password from muser",myconnection);
try
{
SqlParameter myUser = new SqlParameter("@Username",SqlDbType.VarChar, 15);
myUser.Value = user.Trim();
cmd.Parameters.Add(myUser);
SqlParameter myPassword = new SqlParameter("@Password",SqlDbType.VarChar, 15);
myPassword.Value = pass.Trim();
cmd.Parameters.Add(myPassword);
SqlParameter IsValid = new SqlParameter("@IsValid",SqlDbType.Int);
IsValid.Direction = ParameterDirection.Output;
cmd.Parameters.Add(IsValid);
cmd.ExecuteNonQuery();
if ((int)Isvalid.value ==1)
authenticated =true;
}
catch(Exception E)
{
Response.Write(E.Message);
}if ((int)Isvalid.value ==1)
-
April 7th, 2004, 08:41 AM
#2
1) Which line is giving the error?
2) What is the table schema?
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
April 9th, 2004, 10:04 AM
#3
The error's at
Code:
if ((int)Isvalid.value ==1)
because you can't cast directly from string to int.
Code:
if(System.Convert.ToInt64(IsValid.Value) == 1)
-
April 10th, 2004, 05:31 AM
#4
ya ,
but Isvalid.value returns a DBNull ?
why?
can u solve this?
-
April 10th, 2004, 05:34 AM
#5
ya ,
but Isvalid.value returns a DBNull ?
why?
can u solve this?
and there is no schema define for it
-
April 10th, 2004, 09:01 AM
#6
If you allow nulls in the DB (required=NO) then you will get a DBNull when you read it.....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|