Hi
I have House_p table in data base
and insertP.aspx page that in this page users can type data in textbox and click on button after that their information insert into House_p table
below are codes
 
SP
 
 
 
 
USE [behtop]
GO
/****** Object:  StoredProcedure [dbo].[insertproduct3]    Script Date: 04/04/2013 19:10:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insertproduct3]
@Name nvarchar(30),
@Model nvarchar(30)
,@Behcode nvarchar(10)
,@price nvarchar(30)
,@Classification  nvarchar(30)
,@Description nvarchar(max)
,@subset nvarchar(30)
,@id int =0
AS BEGIN
set NOCOUNT ON;
DECLARE @Result INT
SET @Result = 1
  
Declare @H_name nvarchar(30) set @H_name =(select H_name from House_info where behcode=@Behcode )
Declare @BehcodeN nvarchar(30) set @BehcodeN =(select BehcodeN from House_info where behcode=@Behcode )
  
IF @id > 0 AND EXISTS(SELECT behcode FROM House_p WHERE ID = @id and behcode = @Behcode)
BEGIN
  
UPDATE House_p
SET Name=@Name
,[Model]=@Model
,[Description]=@Description
,[Price]=@price
,[Classification]=@Classification
,[Date]=GETDATE()
,H_name=@H_name
,BehcodeN=@BehcodeN
WHERE behcode=@Behcode and ID=@id  
 
SELECT @id id
END
ELSE
BEGIN
   IF (SELECT COUNT(behcode) FROM House_p WHERE behcode = @behcode and BehcodeN='FREE')< 2
     Begin
      INSERT INTO House_p(Name,[Model],[Price],[Classification],[Date],H_name,BehCode,BehcodeN)
      VALUES(@Name,@Model,@price,@Classification ,GETDATE(),@H_name,@Behcode,@BehcodeN)
  
     end
  
ELSE
BEGIN
        SET @Result = 0
         
    END
  
  
  
SELECT @Result
  
  
  
 
end
SELECT CAST(SCOPE_IDENTITY() AS  INT)
  
END
Behind COde
 
 
 
 
 protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
    {
        string data = Server.UrlDecode(Request.QueryString["BehCode"]);
        string price = RadioButton2.Checked ? TextBox1.Text : "null";
        SqlCommand _cmd = new SqlCommand("insertproduct4", _cn);
        _cmd.CommandType = CommandType.StoredProcedure;
        _cn.Open();
        _cmd.Parameters.AddWithValue("@Name", txtname.Text);
        _cmd.Parameters.AddWithValue("@Model", txtmodel.Text);
        _cmd.Parameters.AddWithValue("@Description", CKEditorControl1.Text);
        _cmd.Parameters.AddWithValue("@Price", price);
        _cmd.Parameters.AddWithValue("@Classification", DDL1.SelectedItem.Text);
        _cmd.Parameters.AddWithValue("@subset", DDL2.SelectedItem.Text);
        _cmd.Parameters.AddWithValue("@behcode", data);
        _cmd.Parameters.AddWithValue("@id", Convert.ToInt32(ViewState["Id"]));
        int ID = Convert.ToInt32(_cmd.ExecuteScalar());
        if (ID > 0)
        {
            ViewState["Id"] = ID.ToString();
        }
    
        int Result = Convert.ToInt32(_cmd.ExecuteScalar());
        switch (Result)
        {
            case 1:
                lblerrorV.Visible = false;
                lblerrorV.Text = "";
                Response.Redirect(Request.Url.AbsoluteUri);
                break;
            case 0:
                lblerrorV.Visible = true;
                lblerrorV.Text = "you can enter just 2 item";
                break;
        } 
Now problem is that when I enter data in textbox and click On button to insert it in table it insert data 2 time in table Like below
| 
 Name 
 | 
 Model 
 | 
 Description 
 | 
 Price 
 | 
 Classification 
 | 
 Date 
 | 
 H_name 
 | 
 BehcodeN 
 | 
| 
 TV 
 | 
 78E 
 | 
 Test 
 | 
 123 
 | 
 Electronic 
 | 
 2012 
 | 
 SS 
 | 
 Free 
 | 
| 
 TV 
 | 
 78E 
 | 
 Test 
 | 
 123 
 | 
 Electronic 
 | 
 2012 
 | 
 SS 
 | 
 Free 
 | 
 
why this happen ?
 
Thanks aLot