471,594 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

STRANGE PROBLEM

Im getting that error (It is strange. I Run my programme step by step
pressing f11. im looping SqlCommand in a while loop. The First step runs but
when a enter 2nd step in my loop it returns error ? )

any idea ?

System.Data.SqlClient.SqlException: Procedure or function sp_adduser has
too many arguments specified

My Stored Procedure

CREATE PROCEDURE ST_BOTMARKA
@SiteID INT,
@Marka NVARCHAR (255),
@MarkaLink NVARCHAR (500),
@Tarih NVARCHAR (300)
AS

IF Exists( SELECT 1 FROM TBL_BOTMARKALAR Where MarkaAdi=@Marka AND
SiteID=@SiteID)
UPDATE TBL_BOTMARKALAR SET MarkaLink=@MarkaLink,Tarih=@Tarih
ELSE
INSERT INTO TBL_BOTMARKALAR (SiteID,MarkaAdi,MarkaLink,Tarih) Values
(@SiteID,@Marka,@MarkaLink,@Tarih)
GO


con.ConnectionString = "Initial Catalog=saat;User
Id=sates52;password=abc;Data Source=127.0.0.1";

Today = ConvertDateFunction(System.DateTime.Now);

while (true)

{

con.Open ();

cmd.Connection =con;

cmd.CommandType =CommandType.StoredProcedure;

cmd.CommandText ="ST_BOTMARKA";

cmd.Parameters.Add ("@SiteID",SqlDbType.Int).Value=1;

cmd.Parameters.Add ("@Marka",SqlDbType.NVarChar).Value=Marka;

cmd.Parameters.Add ("@MarkaLink",SqlDbType.NVarChar).Value=MarkaLi nk;

cmd.Parameters.Add ("@Tarih",SqlDbType.NVarChar).Value=Today;

try

{

cmd.ExecuteNonQuery ();

}

catch (Exception e)

{

MessageBox.Show (e.ToString());

}

cmd.Dispose();

con.Close();

}
Jan 29 '07 #1
4 1291
Are you re-using a command without Clear()ing the parameters first?
Alternatively, if performing the same command with different
parameter-values, then add them *once* at the top, and then in the
loop just update the values of each parameter as required.

Marc
Jan 29 '07 #2
Thank you for your reply

I used
cmd.Dispose();
hoping to clear all data which cmd object is keeping.

I used
cmd.Parameters.Clear ();

and it worked.
<in da club>, haber iletisinde şunları
yazdı:Ou*************@TK2MSFTNGP05.phx.gbl...
Im getting that error (It is strange. I Run my programme step by step
pressing f11. im looping SqlCommand in a while loop. The First step runs
but when a enter 2nd step in my loop it returns error ? )

any idea ?

System.Data.SqlClient.SqlException: Procedure or function sp_adduser has
too many arguments specified

My Stored Procedure

CREATE PROCEDURE ST_BOTMARKA
@SiteID INT,
@Marka NVARCHAR (255),
@MarkaLink NVARCHAR (500),
@Tarih NVARCHAR (300)
AS

IF Exists( SELECT 1 FROM TBL_BOTMARKALAR Where MarkaAdi=@Marka AND
SiteID=@SiteID)
UPDATE TBL_BOTMARKALAR SET MarkaLink=@MarkaLink,Tarih=@Tarih
ELSE
INSERT INTO TBL_BOTMARKALAR (SiteID,MarkaAdi,MarkaLink,Tarih) Values
(@SiteID,@Marka,@MarkaLink,@Tarih)
GO


con.ConnectionString = "Initial Catalog=saat;User
Id=sates52;password=abc;Data Source=127.0.0.1";

Today = ConvertDateFunction(System.DateTime.Now);

while (true)

{

con.Open ();

cmd.Connection =con;

cmd.CommandType =CommandType.StoredProcedure;

cmd.CommandText ="ST_BOTMARKA";

cmd.Parameters.Add ("@SiteID",SqlDbType.Int).Value=1;

cmd.Parameters.Add ("@Marka",SqlDbType.NVarChar).Value=Marka;

cmd.Parameters.Add ("@MarkaLink",SqlDbType.NVarChar).Value=MarkaLi nk;

cmd.Parameters.Add ("@Tarih",SqlDbType.NVarChar).Value=Today;

try

{

cmd.ExecuteNonQuery ();

}

catch (Exception e)

{

MessageBox.Show (e.ToString());

}

cmd.Dispose();

con.Close();

}


Jan 29 '07 #3

>Im getting that error (It is strange. I Run my programme step by step
pressing f11. im looping SqlCommand in a while loop. The First step runs but
when a enter 2nd step in my loop it returns error ? )

any idea ?

System.Data.SqlClient.SqlException: Procedure or function sp_adduser has
too many arguments specified

My Stored Procedure

CREATE PROCEDURE ST_BOTMARKA
@SiteID INT,
@Marka NVARCHAR (255),
@MarkaLink NVARCHAR (500),
@Tarih NVARCHAR (300)
AS

IF Exists( SELECT 1 FROM TBL_BOTMARKALAR Where MarkaAdi=@Marka AND
SiteID=@SiteID)
UPDATE TBL_BOTMARKALAR SET MarkaLink=@MarkaLink,Tarih=@Tarih
ELSE
INSERT INTO TBL_BOTMARKALAR (SiteID,MarkaAdi,MarkaLink,Tarih) Values
(@SiteID,@Marka,@MarkaLink,@Tarih)
GO


con.ConnectionString = "Initial Catalog=saat;User
Id=sates52;password=abc;Data Source=127.0.0.1";

Today = ConvertDateFunction(System.DateTime.Now);

while (true)

{

con.Open ();

cmd.Connection =con;

cmd.CommandType =CommandType.StoredProcedure;

cmd.CommandText ="ST_BOTMARKA";

cmd.Parameters.Add ("@SiteID",SqlDbType.Int).Value=1;

cmd.Parameters.Add ("@Marka",SqlDbType.NVarChar).Value=Marka;

cmd.Parameters.Add ("@MarkaLink",SqlDbType.NVarChar).Value=MarkaLi nk;

cmd.Parameters.Add ("@Tarih",SqlDbType.NVarChar).Value=Today;

try

{

cmd.ExecuteNonQuery ();

}

catch (Exception e)

{

MessageBox.Show (e.ToString());

}

cmd.Dispose();

con.Close();

}

You add parameters to the stored procedure in a loop.So u add the parameters while true.You should not add parameters in a loop

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
Feb 1 '07 #4
Encik,

At the first place I do not think you should use while (true). What is the
reason you use while (true) ? It is damn bad practise lah encik.

You memang perlu pakai condition lah

chanmm

"kmitzu" <pr********@yahoo.comwrote in message
news:eb**************@TK2MSFTNGP06.phx.gbl...
>
>>Im getting that error (It is strange. I Run my programme step by step
pressing f11. im looping SqlCommand in a while loop. The First step runs
but
when a enter 2nd step in my loop it returns error ? )

any idea ?

System.Data.SqlClient.SqlException: Procedure or function sp_adduser has
too many arguments specified

My Stored Procedure

CREATE PROCEDURE ST_BOTMARKA
@SiteID INT,
@Marka NVARCHAR (255),
@MarkaLink NVARCHAR (500),
@Tarih NVARCHAR (300)
AS

IF Exists( SELECT 1 FROM TBL_BOTMARKALAR Where MarkaAdi=@Marka AND
SiteID=@SiteID)
UPDATE TBL_BOTMARKALAR SET MarkaLink=@MarkaLink,Tarih=@Tarih
ELSE
INSERT INTO TBL_BOTMARKALAR (SiteID,MarkaAdi,MarkaLink,Tarih) Values
(@SiteID,@Marka,@MarkaLink,@Tarih)
GO


con.ConnectionString = "Initial Catalog=saat;User
Id=sates52;password=abc;Data Source=127.0.0.1";

Today = ConvertDateFunction(System.DateTime.Now);

while (true)

{

con.Open ();

cmd.Connection =con;

cmd.CommandType =CommandType.StoredProcedure;

cmd.CommandText ="ST_BOTMARKA";

cmd.Parameters.Add ("@SiteID",SqlDbType.Int).Value=1;

cmd.Parameters.Add ("@Marka",SqlDbType.NVarChar).Value=Marka;

cmd.Parameters.Add ("@MarkaLink",SqlDbType.NVarChar).Value=MarkaLi nk;

cmd.Parameters.Add ("@Tarih",SqlDbType.NVarChar).Value=Today;

try

{

cmd.ExecuteNonQuery ();

}

catch (Exception e)

{

MessageBox.Show (e.ToString());

}

cmd.Dispose();

con.Close();

}

You add parameters to the stored procedure in a loop.So u add the
parameters while true.You should not add parameters in a loop

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
Feb 3 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Paul Drummond | last post: by
25 posts views Thread by Neil Ginsberg | last post: by
1 post views Thread by Sam Kong | last post: by
11 posts views Thread by Martin Joergensen | last post: by
8 posts views Thread by Dox33 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | 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.