exec command in stored procedure depends on condition

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 28
Reputation: u4umang2001 is an unknown quantity at this point 
Solved Threads: 0
u4umang2001's Avatar
u4umang2001 u4umang2001 is offline Offline
Light Poster

exec command in stored procedure depends on condition

 
0
  #1
Feb 6th, 2008
Hi

i want to insert the email into a table,
i pass the parameter to the stored procedure

if this email_id doesnt exists in the table
only then it should be inserted into the table...

how to do this using a stored procedure

please help
its urgent!!!
Thanks & Regards
Umang
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: exec command in stored procedure depends on condition

 
0
  #2
Feb 6th, 2008
this t-sql below does what you want :

declare @email nvarchar(50)
set @email = 'test'
if not exists (select * from yourtable where email=@email )
insert into yourtable(email) values(@email )
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 28
Reputation: u4umang2001 is an unknown quantity at this point 
Solved Threads: 0
u4umang2001's Avatar
u4umang2001 u4umang2001 is offline Offline
Light Poster

Re: exec command in stored procedure depends on condition

 
0
  #3
Feb 6th, 2008
thanks


but i want to display the message also if email exists

then wht can i do for that???
Thanks & Regards
Umang
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 28
Reputation: u4umang2001 is an unknown quantity at this point 
Solved Threads: 0
u4umang2001's Avatar
u4umang2001 u4umang2001 is offline Offline
Light Poster

Re: exec command in stored procedure depends on condition

 
0
  #4
Feb 6th, 2008
how can i show that message at my .aspx page???
Thanks & Regards
Umang
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: exec command in stored procedure depends on condition

 
0
  #5
Feb 6th, 2008
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
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 28
Reputation: u4umang2001 is an unknown quantity at this point 
Solved Threads: 0
u4umang2001's Avatar
u4umang2001 u4umang2001 is offline Offline
Light Poster

Re: exec command in stored procedure depends on condition

 
0
  #6
Feb 6th, 2008
no
its not working...
Thanks & Regards
Umang
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: exec command in stored procedure depends on condition

 
0
  #7
Feb 6th, 2008
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 :
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC