471,066 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

SQL 2005 INSERT statement inserts two rows

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)

Declare @temp1 int,
@temp2 int,
@temp3 int,
@temp4 uniqueidentifier;
/*Set NOCOUNT on*/

SET @variable1=(SELECT value1 from table1 where <condition>)
SET @variable2=(SELECT value2 from table1 where <condition>)

SET @variable1=(SELECT value3 from table1 where <condition>)

SET @variable1=(SELECT value4 from table1 where <condition>)

INSERT INTO mytable (field1,field2,field3,field4,field5,field6,field7, field8,field9,field10,field11,field12,field13)
VALUES (variable1,variable2,variable3,variable4,variable5 ,variable6,variable7,variable8,variable9,variable1 0,variable11,variable12,variable13);

SELECT CAST(scope_identity() AS int);

/*Reset NOCOUNT*/



[end of CODE]
Here is my ASP.NET part.

[CODE} code goes here
int thisvalue1;
string connStr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirecto ry|\\learning.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(connStr);
SqlCommand command = new SqlCommand("myProcedure", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@variable1",value1));
command.Parameters.Add(new SqlParameter("@variable2",value2));
command.Parameters.Add(new SqlParameter("@variable3",value3));
command.Parameters.Add(new SqlParameter("@variable4",value4));
command.Parameters.Add(new SqlParameter("@variable5",value5));
command.Parameters.Add(new SqlParameter("@variable6",value6));
command.Parameters.Add(new SqlParameter("@variable7",value7));
command.Parameters.Add(new SqlParameter("@variable8",value8));
command.Parameters.Add(new SqlParameter("@variable9",value9));
command.Parameters.Add(new SqlParameter("@variable10",value10));
command.Parameters.Add(new SqlParameter("@variable11",value11));
command.Parameters.Add(new SqlParameter("@variable12",value12));
command.Parameters.Add(new SqlParameter("@variable13",value13));

Int32 tempPrjID=(Int32)command.ExecuteScalar();
return thisPrjID;

[end of code]
================================================== ===
Dec 25 '07 #1
2 2161
I found the problem. It occurred because it happend like this:

One: I put OnClick="CalculateMyData" in the aspx page.
Second: I again put the delegate in Page_Init.
So the event fired twice.
I am happy I found the solution.
Dec 31 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by traceable1 | last post: by
11 posts views Thread by Sezai YILMAZ | last post: by
20 posts views Thread by Mark Harrison | last post: by
46 posts views Thread by dunleav1 | last post: by
4 posts views Thread by ~john | last post: by
4 posts views Thread by Michel Esber | last post: by
6 posts views Thread by Michel Esber | last post: by
24 posts views Thread by Henry J. | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.