J
Jeff
ASP.NET 2.0
Below is the source code of my stored procedure and some C# code from my
webproject. The PROBLEM is that the stored procedure for example returns the
value 1, but in the C# code variable t (int t =
Convert.ToInt32(cmd.ExecuteScalar()) get the value 0, but it should be
1.....
*************** table and stored procedure **************
create table Location (
Id uniqueidentifier not null,
Description nvarchar(100),
CONSTRAINT PK_Location PRIMARY KEY (Id)
)
CREATE PROCEDURE dbo.Test @app uniqueidentifier
AS
SET NOCOUNT ON
DECLARE @count int;
SELECT @count = count(*) from Location where Id = @app;
RETURN @count;
********************* C# code ***********************
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("Test", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@app", SqlDbType.UniqueIdentifier).Value = app;
cn.Open();
int t = Convert.ToInt32(cmd.ExecuteScalar());
if (t == 0)
return false;
else
return true;
}
What must I do so the C# code catches the correct value?
Best Regards!
Jeff
Below is the source code of my stored procedure and some C# code from my
webproject. The PROBLEM is that the stored procedure for example returns the
value 1, but in the C# code variable t (int t =
Convert.ToInt32(cmd.ExecuteScalar()) get the value 0, but it should be
1.....
*************** table and stored procedure **************
create table Location (
Id uniqueidentifier not null,
Description nvarchar(100),
CONSTRAINT PK_Location PRIMARY KEY (Id)
)
CREATE PROCEDURE dbo.Test @app uniqueidentifier
AS
SET NOCOUNT ON
DECLARE @count int;
SELECT @count = count(*) from Location where Id = @app;
RETURN @count;
********************* C# code ***********************
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("Test", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@app", SqlDbType.UniqueIdentifier).Value = app;
cn.Open();
int t = Convert.ToInt32(cmd.ExecuteScalar());
if (t == 0)
return false;
else
return true;
}
What must I do so the C# code catches the correct value?
Best Regards!
Jeff