J
Jeff
Hey
asp.net 2.0
My code below crashes at the "return (int)cmd.Parameters["@return"].Value;"
line. In the debugging window I see that when this exception occur, the
"return (int)cmd.Parameters["@return"].Value;" has a NULL value....
public override int SendMessage(MessageDetails message)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@receiver", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@sender", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@title", SqlDbType.NVarChar).Value =
message.Title;
cmd.Parameters.Add("@body", SqlDbType.NVarChar).Value =
message.Body;
cmd.Parameters.Add("@return", SqlDbType.Int).Direction =
ParameterDirection.Output;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (int)cmd.Parameters["@return"].Value;
}
}
This is the stored procdure called in the method:
ALTER PROCEDURE dbo.AH_network_SendMessages
@sender nvarchar(256),
@receiver nvarchar(256),
@title nvarchar(100),
@body nvarchar(2000),
@return int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AH_Messages (sender, receiver, title, body)
VALUES (@sender, @receiver, @title, @body);
set @return = 1;
select 1;
END
Please, what am I doing wrong here?
Jeff
asp.net 2.0
My code below crashes at the "return (int)cmd.Parameters["@return"].Value;"
line. In the debugging window I see that when this exception occur, the
"return (int)cmd.Parameters["@return"].Value;" has a NULL value....
public override int SendMessage(MessageDetails message)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@receiver", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@sender", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@title", SqlDbType.NVarChar).Value =
message.Title;
cmd.Parameters.Add("@body", SqlDbType.NVarChar).Value =
message.Body;
cmd.Parameters.Add("@return", SqlDbType.Int).Direction =
ParameterDirection.Output;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (int)cmd.Parameters["@return"].Value;
}
}
This is the stored procdure called in the method:
ALTER PROCEDURE dbo.AH_network_SendMessages
@sender nvarchar(256),
@receiver nvarchar(256),
@title nvarchar(100),
@body nvarchar(2000),
@return int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AH_Messages (sender, receiver, title, body)
VALUES (@sender, @receiver, @title, @body);
set @return = 1;
select 1;
END
Please, what am I doing wrong here?
Jeff