HI
I have 2 table in database
Estate_p Table
Id
|
Name
|
Date
|
behcode
|
code
|
1
|
Sara
|
2012/11/11
|
1111
|
22556
|
2
|
Jack
|
2012/11/12
|
1112
|
223564
|
and Advertisment Tabel
Id
|
Name
|
Date
|
behcode
|
code
|
days
|
1
|
Sara
|
2012/11/11
|
1111
|
|
|
|
|
|
|
|
|
and I have 2 textbox and one imagebutton and one label (that show error message) and one gridview in my page
in txtcode users enter code
and in txtad enter number
I want when users click on Imagebutton if there exist code( In Estate_p code column) (that users enter code in txtcode) when they click on button it insert data from estate_p into Advertisment tabel and if there wasn't code in estate_p tabel it show error that i define in lable:
I wrote below code
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);
int Result = _cmd.ExecuteNonQuery();
if (Result > 0)
{
lblerrorV.Visible = false;
}
else
{
lblerrorV.Visible = true;
}
_cn.Close();
BindData();
txtcode.Text = " ";
txtad.Text = " ";
and SP
USE [behtop]
GO
/****** Object: StoredProcedure [dbo].[insertAD] Script Date: 11/10/2012 19:29:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insertAD]
@day int
,@behcode nvarchar(10)
,@code varchar(20)
as
begin
set NOCOUNT ON;
insert into advertisment(behcode,date
Name,days)
select behcode,date,name ,@day
from Estate_p
where behcode=@behcode and Code=@code
end
when I enter wrong code in txtcode it didn't insert any thing in tabel and show error label but after that when I enter right code it again didn't insert any thing in tabel and show error label too
I want when users enter right code it insert data from estate_p tabel into Advertisment tabel and if usersenter wrong code it didn't insert data and show laberror
Best regards