Greetings.
I suppose people out there can help in my problem.
I am using sql server of microsoft visual studio 2005 itself. I have created a stored procedure which is give below. It works fine but it always inserts two records into the database. All columns of the two rows are same but the primary key is different which is no surprise. Please help me get out of this problem.
--------------------------------
[CODE] code goes here
--------------------------------
ALTER PROCEDURE dbo.myProcedure
(
@variable1 nvarchar(50),
@variable2 nvarchar(500),
@variable3 datetime,
@variable4 datetime,
@variable5 bit,
@variable6 tinyint,
@variable7 tinyint,
@variable8 nvarchar(50),
@variable9 nvarchar(50),
@variable10 nvarchar(50),
@variable11 nvarchar(256),
@variable12 int,
@variable13 nvarchar(50)
)
AS
BEGIN
Declare @temp1 int,
@temp2 int,
@temp3 int,
@temp4 uniqueidentifie r;
/*Set NOCOUNT on*/
SET NOCOUNT ON ;
SET @variable1=(SEL ECT value1 from table1 where <condition>)
SET @variable2=(SEL ECT value2 from table1 where <condition>)
SET @variable1=(SEL ECT value3 from table1 where <condition>)
SET @variable1=(SEL ECT value4 from table1 where <condition>)
INSERT INTO mytable (field1,field2, field3,field4,f ield5,field6,fi eld7,field8,fie ld9,field10,fie ld11,field12,fi eld13)
VALUES (variable1,vari able2,variable3 ,variable4,vari able5,variable6 ,variable7,vari able8,variable9 ,variable10,var iable11,variabl e12,variable13) ;
SELECT CAST(scope_iden tity() AS int);
/*Reset NOCOUNT*/
SET NOCOUNT OFF
RETURN
END
[end of CODE]
----------------------------------------------------
Here is my ASP.NET part.
[CODE} code goes here
------------------------------------------------------------------
int thisvalue1;
string connStr = "Data Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\learn ing.mdf;Integra ted Security=True;U ser Instance=True";
SqlConnection con = new SqlConnection(c onnStr);
SqlCommand command = new SqlCommand("myP rocedure", con);
command.Command Type = CommandType.Sto redProcedure;
command.Paramet ers.Add(new SqlParameter("@ variable1",valu e1));
command.Paramet ers.Add(new SqlParameter("@ variable2",valu e2));
command.Paramet ers.Add(new SqlParameter("@ variable3",valu e3));
command.Paramet ers.Add(new SqlParameter("@ variable4",valu e4));
command.Paramet ers.Add(new SqlParameter("@ variable5",valu e5));
command.Paramet ers.Add(new SqlParameter("@ variable6",valu e6));
command.Paramet ers.Add(new SqlParameter("@ variable7",valu e7));
command.Paramet ers.Add(new SqlParameter("@ variable8",valu e8));
command.Paramet ers.Add(new SqlParameter("@ variable9",valu e9));
command.Paramet ers.Add(new SqlParameter("@ variable10",val ue10));
command.Paramet ers.Add(new SqlParameter("@ variable11",val ue11));
command.Paramet ers.Add(new SqlParameter("@ variable12",val ue12));
command.Paramet ers.Add(new SqlParameter("@ variable13",val ue13));
con.Open();
Int32 tempPrjID=(Int3 2)command.Execu teScalar();
con.Close();
thisPrjID=(int) tempPrjID;
return thisPrjID;
[end of code]
=============== =============== =============== ========
I suppose people out there can help in my problem.
I am using sql server of microsoft visual studio 2005 itself. I have created a stored procedure which is give below. It works fine but it always inserts two records into the database. All columns of the two rows are same but the primary key is different which is no surprise. Please help me get out of this problem.
--------------------------------
[CODE] code goes here
--------------------------------
ALTER PROCEDURE dbo.myProcedure
(
@variable1 nvarchar(50),
@variable2 nvarchar(500),
@variable3 datetime,
@variable4 datetime,
@variable5 bit,
@variable6 tinyint,
@variable7 tinyint,
@variable8 nvarchar(50),
@variable9 nvarchar(50),
@variable10 nvarchar(50),
@variable11 nvarchar(256),
@variable12 int,
@variable13 nvarchar(50)
)
AS
BEGIN
Declare @temp1 int,
@temp2 int,
@temp3 int,
@temp4 uniqueidentifie r;
/*Set NOCOUNT on*/
SET NOCOUNT ON ;
SET @variable1=(SEL ECT value1 from table1 where <condition>)
SET @variable2=(SEL ECT value2 from table1 where <condition>)
SET @variable1=(SEL ECT value3 from table1 where <condition>)
SET @variable1=(SEL ECT value4 from table1 where <condition>)
INSERT INTO mytable (field1,field2, field3,field4,f ield5,field6,fi eld7,field8,fie ld9,field10,fie ld11,field12,fi eld13)
VALUES (variable1,vari able2,variable3 ,variable4,vari able5,variable6 ,variable7,vari able8,variable9 ,variable10,var iable11,variabl e12,variable13) ;
SELECT CAST(scope_iden tity() AS int);
/*Reset NOCOUNT*/
SET NOCOUNT OFF
RETURN
END
[end of CODE]
----------------------------------------------------
Here is my ASP.NET part.
[CODE} code goes here
------------------------------------------------------------------
int thisvalue1;
string connStr = "Data Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\learn ing.mdf;Integra ted Security=True;U ser Instance=True";
SqlConnection con = new SqlConnection(c onnStr);
SqlCommand command = new SqlCommand("myP rocedure", con);
command.Command Type = CommandType.Sto redProcedure;
command.Paramet ers.Add(new SqlParameter("@ variable1",valu e1));
command.Paramet ers.Add(new SqlParameter("@ variable2",valu e2));
command.Paramet ers.Add(new SqlParameter("@ variable3",valu e3));
command.Paramet ers.Add(new SqlParameter("@ variable4",valu e4));
command.Paramet ers.Add(new SqlParameter("@ variable5",valu e5));
command.Paramet ers.Add(new SqlParameter("@ variable6",valu e6));
command.Paramet ers.Add(new SqlParameter("@ variable7",valu e7));
command.Paramet ers.Add(new SqlParameter("@ variable8",valu e8));
command.Paramet ers.Add(new SqlParameter("@ variable9",valu e9));
command.Paramet ers.Add(new SqlParameter("@ variable10",val ue10));
command.Paramet ers.Add(new SqlParameter("@ variable11",val ue11));
command.Paramet ers.Add(new SqlParameter("@ variable12",val ue12));
command.Paramet ers.Add(new SqlParameter("@ variable13",val ue13));
con.Open();
Int32 tempPrjID=(Int3 2)command.Execu teScalar();
con.Close();
thisPrjID=(int) tempPrjID;
return thisPrjID;
[end of code]
=============== =============== =============== ========
Comment