ok
for showing error message I modify your query like below
ALTER procedure [dbo].[insertAD]
@day int
,@behcode nvarchar(10)
,@code varchar(20)
,@labeltext1 nvarchar(50) OUTPUT
as
BEGIN
SET NOCOUNT ON;
DECLARE @Result INT
SET @Result = 1
IF EXISTS(SELECT behcode FROM Estate_p WHERE Code=@code )
BEGIN
IF (SELECT COUNT(behcode) FROM advertisment WHERE behcode = @behcode )< 4
BEGIN
INSERT INTO advertisment(behcode,[date], Name,[days])
SELECT behcode,[date],name ,@day
FROM Estate_p
WHERE behcode=@behcode and Code=@code
END
ELSE
BEGIN
SET @Result = 2
SELECT @labelText1='you can enter just 4 item'
END
END
ELSE
BEGIN
SET @Result = 0
@labelText1='please enter correct number'
END
SELECT @Result
END
and Img button event
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string data = Server.UrlDecode(Request.QueryString["BehCode"]);
SqlCommand _cmd = new SqlCommand("insertAD", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();
_cmd.Parameters.AddWithValue("@behcode", data);
_cmd.Parameters.AddWithValue("@code", txtcode.Text);
_cmd.Parameters.AddWithValue("@day", txtad.Text);
_cmd.Parameters.Add("@labeltext1", SqlDbType.NVarChar, 50);
bool Result = Convert.ToBoolean(_cmd.ExecuteScalar());
if (Result)
{
lblerrorV.Visible = false;
Response.Redirect(Request.Url.AbsoluteUri);
}
else
{
lblerrorV.Text = _cmd.Parameters["@labeltext1"].Value.ToString();
}
_cn.Close();
BindData();
}
but when I click on image button occure this error
Procedure or function 'insertAD' expects parameter '@labeltext1', which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or function 'insertAD' expects parameter '@labeltext1', which was not supplied.
Source Error:
Line 242: _cmd.Parameters.Add("@labeltext1", SqlDbType.NVarChar, 50);
Line 243:
Line 244: bool Result = Convert.ToBoolean(_cmd.ExecuteScalar()); |
do I modify query correctly?