| | |
exec command in stored procedure depends on condition
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
execute the following query in ExecuteScalar mode, and display the return value to the user.
declare @email nvarchar(50)
set @email = 'test'
if not exists (select * from yourtable where email=@email )
begin
insert into yourtable(email) values(@email )
select 'inserted successfully'
end
else
begin
select 'the provided email already exists in our records'
end
declare @email nvarchar(50)
set @email = 'test'
if not exists (select * from yourtable where email=@email )
begin
insert into yourtable(email) values(@email )
select 'inserted successfully'
end
else
begin
select 'the provided email already exists in our records'
end
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
ok i will go step by step :
first create your stored procedure in sql server with the following :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE myInsertProcedure
@email nvarchar(50)
AS
BEGIN
SET NOCOUNT ON;
if not exists (select * from yourtable where email=@email )
begin
insert into yourtable(email) values(@email )
select 'inserted successfully'
end
else
begin
select 'the provided email already exists in our records'
end
END
GO
then go to your aspx page and create the markup below :
<asp: TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp: Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
lastly double click your button and type the following :
i tried this creating a sample application, it works, just modify your connection string and adjust everything according to your webpage
first create your stored procedure in sql server with the following :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE myInsertProcedure
@email nvarchar(50)
AS
BEGIN
SET NOCOUNT ON;
if not exists (select * from yourtable where email=@email )
begin
insert into yourtable(email) values(@email )
select 'inserted successfully'
end
else
begin
select 'the provided email already exists in our records'
end
END
GO
then go to your aspx page and create the markup below :
<asp: TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp: Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
lastly double click your button and type the following :
SqlConnection sqlCon = new SqlConnection("Data Source=ALPC28\\SERKANS2005;Initial Catalog=denemeler;Integrated Security=True;Pooling=False");
SqlCommand sqlCom = new SqlCommand();
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.CommandText = "myInsertProcedure";
sqlCom.Connection = sqlCon;
SqlParameter sqlPar = new SqlParameter("@email", SqlDbType.VarChar);
sqlPar.Value = TextBox1.Text;
sqlCom.Parameters.Add(sqlPar);
string notification;
sqlCon.Open();
notification = sqlCom.ExecuteScalar().ToString();
sqlCon.Close();
Response.Write(notification);i tried this creating a sample application, it works, just modify your connection string and adjust everything according to your webpage
Due to lack of freedom of speech, i no longer post on this website.
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: ASP.Net Development India
- Next Thread: Socket programming on Web Server
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos application asp asp.net bc30451 bottomasp.net box browser button c# c#gridviewcolumn checkbox click commonfunctions confirmationcodegeneration css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fileuploader fill flash form formatdecimal forms formview grid gridview gudi homeedition hosting iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security select silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos view virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers






