Click here to Skip to main content
15,890,932 members
Home / Discussions / C#
   

C#

 
AnswerRe: Data Structure Pin
sph3rex16-Nov-08 8:31
sph3rex16-Nov-08 8:31 
AnswerRe: Data Structure Pin
User 665816-Nov-08 8:44
User 665816-Nov-08 8:44 
AnswerRe: Data Structure Pin
Mark Churchill16-Nov-08 12:49
Mark Churchill16-Nov-08 12:49 
GeneralRe: Data Structure Pin
Alan Balkany17-Nov-08 4:03
Alan Balkany17-Nov-08 4:03 
GeneralRe: Data Structure Pin
Mark Churchill17-Nov-08 11:42
Mark Churchill17-Nov-08 11:42 
AnswerRe: Data Structure Pin
Guffa16-Nov-08 13:05
Guffa16-Nov-08 13:05 
AnswerRe: Data Structure Pin
Mycroft Holmes16-Nov-08 15:15
professionalMycroft Holmes16-Nov-08 15:15 
QuestionCasting Error Pin
Vimalsoft(Pty) Ltd16-Nov-08 4:02
professionalVimalsoft(Pty) Ltd16-Nov-08 4:02 
Good Afternoon All

Happy Sunday

I have the Following SP, that keeps track of the users Role in my ASP.NET app.

Create Proc Roles
(
@Username varchar(55),
@Role int OUTPUT
)
as 
set @Role = (Select User_Type from dbo.Logins
where Username = @Username)
Select Case @Role
when 1 then 1
when 2 then 2
else
0
End


Now this SP will only Bring Back 1,2 or 0

when i test it from like this

declare @role int
exec dbo.get_role 'dfdf',@Role out


its Fine, now lets go to my Problem. Am using it in my BLL and DAL like this ,


DAL


int Results;
con = new SqlConnection(strcon);
cmdselect = new sqlcommand();
cmdselect.CommandText= "dbo.Get_Role";
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
cmdselect.Parameter.Add("@Username,SqlDBType.Varchar,55).Value= Username;
cmdselect.Parameters.Add("@Role",SqlDbType.Int);
cmdselect.Parameters["@Role"].Direction=  ParameterDirection.OutPut;
try
{
Con.Open();
cmdselect.ExecuteNonQuery();
Results = (int) cmdselect.Parameters["@Role"].Value;}
catch(SqlException)
{
throw;
}
Finally
{
con.Close();
}
return Results;
}

The Problem is in the Casting bolded part. My SP Returns "0", if there is no Role Found.

i get this Error on my App
Specified cast is not Valid 

What is Wrong

Thanks

Vuyiswa Maseko,

Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding

VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za


AnswerRe: Casting Error Pin
Wendelius16-Nov-08 4:38
mentorWendelius16-Nov-08 4:38 
GeneralRe: Casting Error Pin
Guffa16-Nov-08 6:58
Guffa16-Nov-08 6:58 
GeneralRe: Casting Error Pin
Wendelius16-Nov-08 9:44
mentorWendelius16-Nov-08 9:44 
AnswerRe: Casting Error Pin
Guffa16-Nov-08 7:01
Guffa16-Nov-08 7:01 
GeneralRe: Casting Error Pin
Vimalsoft(Pty) Ltd16-Nov-08 9:25
professionalVimalsoft(Pty) Ltd16-Nov-08 9:25 
GeneralRe: Casting Error Pin
Guffa16-Nov-08 13:10
Guffa16-Nov-08 13:10 
Answer[Resolved]Re: Casting Error Pin
Vimalsoft(Pty) Ltd16-Nov-08 19:29
professionalVimalsoft(Pty) Ltd16-Nov-08 19:29 
QuestionSolution for Tower of Hanoi with Breadth First Search Algorithm ? Pin
Mohammad Dayyan16-Nov-08 2:34
Mohammad Dayyan16-Nov-08 2:34 
AnswerRe: Solution for Tower of Hanoi with Breadth First Search Algorithm ? PinPopular
#realJSOP16-Nov-08 3:01
mve#realJSOP16-Nov-08 3:01 
GeneralRe: Solution for Tower of Hanoi with Breadth First Search Algorithm ? Pin
Mohammad Dayyan16-Nov-08 16:16
Mohammad Dayyan16-Nov-08 16:16 
AnswerRe: Solution for Tower of Hanoi with Breadth First Search Algorithm ? Pin
Christian Graus16-Nov-08 12:58
protectorChristian Graus16-Nov-08 12:58 
GeneralRe: Solution for Tower of Hanoi with Breadth First Search Algorithm ? Pin
Mohammad Dayyan16-Nov-08 16:15
Mohammad Dayyan16-Nov-08 16:15 
GeneralRe: Solution for Tower of Hanoi with Breadth First Search Algorithm ? Pin
Paul Conrad16-Nov-08 17:46
professionalPaul Conrad16-Nov-08 17:46 
Questiondatabind pictureBox control to Northwind Employees table Pin
papori123416-Nov-08 2:25
papori123416-Nov-08 2:25 
Question32Bits Depth Images to 24Bits Depth Image c# Pin
saberbladez16-Nov-08 2:11
saberbladez16-Nov-08 2:11 
AnswerRe: 32Bits Depth Images to 24Bits Depth Image c# Pin
#realJSOP16-Nov-08 3:02
mve#realJSOP16-Nov-08 3:02 
AnswerRe: 32Bits Depth Images to 24Bits Depth Image c# Pin
Christian Graus16-Nov-08 13:00
protectorChristian Graus16-Nov-08 13:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.