Click here to Skip to main content
15,897,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: how can made c#.net messenger? Pin
Christian Graus22-Dec-08 11:18
protectorChristian Graus22-Dec-08 11:18 
GeneralRe: how can made c#.net messenger? Pin
EliottA22-Dec-08 11:20
EliottA22-Dec-08 11:20 
GeneralRe: how can made c#.net messenger? Pin
PIEBALDconsult22-Dec-08 13:10
mvePIEBALDconsult22-Dec-08 13:10 
GeneralRe: how can made c#.net messenger? Pin
Christian Graus22-Dec-08 13:45
protectorChristian Graus22-Dec-08 13:45 
GeneralRe: how can made c#.net messenger? Pin
PIEBALDconsult22-Dec-08 14:25
mvePIEBALDconsult22-Dec-08 14:25 
GeneralRe: how can made c#.net messenger? Pin
Christian Graus22-Dec-08 17:01
protectorChristian Graus22-Dec-08 17:01 
GeneralRe: how can made c#.net messenger? Pin
PIEBALDconsult23-Dec-08 12:22
mvePIEBALDconsult23-Dec-08 12:22 
QuestionEfficient way of accessing a Boolean from SQL Server Pin
Andreas_198322-Dec-08 9:35
Andreas_198322-Dec-08 9:35 
Hi,

I don't know if this was more suited to the database message board or not but I think my question is more to do with my code rather than the database.

I have a basic table with a few columns. One of them is a Bit type and is effectively a flag. All I want to do is get the flag value for a given ID.

I've tried using an output parameter in a stored procedure but I don't know the best way of retrieving the flag value and converting it to a Boolean in code. I don't think a SqlDataReader is ideal because it's only one value I want to return.

ALTER PROCEDURE SP_UserValid
	@ID    INT,
	@Valid BIT OUTPUT
AS
	SET NOCOUNT ON;
	SET @Valid = (SELECT [Valid] FROM tUsers WHERE ID = @ID)


Here's my code:

SqlConnection connection = new SqlConnection(_ConnectionString);
SqlCommand cmd           = new SqlCommand();
cmd.Connection           = connection;
cmd.CommandType          = CommandType.StoredProcedure;
cmd.CommandText          = "SP_UserValid";
cmd.Parameters.Add(new SqlParameter("@ID", userID));
cmd.Parameters.Add(new SqlParameter("@Valid", bValid));
cmd.Parameters["@Valid"].SqlDbType = SqlDbType.Bit;
cmd.Parameters["@Valid"].Direction = ParameterDirection.InputOutput;

connection.Open();
cmd.ExecuteNonQuery();

// How do I get the "Valid" as a Boolean value?

cmd.Connection.Close()


Thanks for looking Smile | :)
AnswerRe: Efficient way of accessing a Boolean from SQL Server Pin
Not Active22-Dec-08 10:02
mentorNot Active22-Dec-08 10:02 
AnswerRe: Efficient way of accessing a Boolean from SQL Server Pin
shea-c422-Dec-08 10:24
shea-c422-Dec-08 10:24 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
Andreas_198322-Dec-08 10:59
Andreas_198322-Dec-08 10:59 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
Mycroft Holmes22-Dec-08 15:07
professionalMycroft Holmes22-Dec-08 15:07 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
jchandramouli22-Dec-08 18:41
jchandramouli22-Dec-08 18:41 
GeneralRe: Efficient way of accessing a Boolean from SQL Server Pin
Mycroft Holmes22-Dec-08 18:50
professionalMycroft Holmes22-Dec-08 18:50 
QuestionVS2008 and Updating controls ? [modified] Pin
Mike Bluett22-Dec-08 8:43
Mike Bluett22-Dec-08 8:43 
AnswerRe: VS2008 and Updating controls ? Pin
Not Active22-Dec-08 10:14
mentorNot Active22-Dec-08 10:14 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 7:07
Mike Bluett24-Dec-08 7:07 
GeneralRe: VS2008 and Updating controls ? Pin
Not Active24-Dec-08 8:16
mentorNot Active24-Dec-08 8:16 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 9:10
Mike Bluett24-Dec-08 9:10 
GeneralRe: VS2008 and Updating controls ? Pin
Not Active24-Dec-08 9:46
mentorNot Active24-Dec-08 9:46 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 9:57
Mike Bluett24-Dec-08 9:57 
AnswerRe: VS2008 and Updating controls ? Pin
Dragonfly_Lee22-Dec-08 21:19
Dragonfly_Lee22-Dec-08 21:19 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett23-Dec-08 10:32
Mike Bluett23-Dec-08 10:32 
GeneralRe: VS2008 and Updating controls ? Pin
Dragonfly_Lee23-Dec-08 21:10
Dragonfly_Lee23-Dec-08 21:10 
GeneralRe: VS2008 and Updating controls ? Pin
Mike Bluett24-Dec-08 7:05
Mike Bluett24-Dec-08 7:05 

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.