By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,991 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,991 IT Pros & Developers. It's quick & easy.

STRANGE PROBLEM

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a

>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

P: n/a
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.