SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Must declare scalar variable???
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

magnetica
Starting Member

36 Posts

Posted - 08/31/2006 :  06:31:11  Show Profile  Click to see magnetica's MSN Messenger address  Reply with Quote
OK i have my stored procedure all set up and working.. But when i try and add a second variable called @iuser and then after i execute the stored procedure, i get an error saying:-
ERROR
"Must declare scalar variable @iuser"

Here is the code i am using in my stored proc, also my stored proc worked fine before i used a second variable??!

//BEGIN

ALTER PROCEDURE [dbo].[putpending]
(@cuuser nvarchar(1000), @iuser nvarchar(1000))

AS
Declare @sql nvarchar(1000)

SELECT @sql =
'INSERT INTO ' +
@cuuser +
' (Pending) VALUES (@iuser)'

EXECUTE (@sql)

RETURN
//END

And i know my VB.NET code is working but i will put it in anyway:-

//BEGIN

'variables
Dim user As String
user = Profile.UserName
Dim intenduser As String
intenduser = DetailsView1.Rows(0).Cells(1).Text.ToString()

'connection settings
Dim cs As String
cs = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\friends.mdf;Integrated Security=True;User Instance=True"
Dim scn As New SqlConnection(cs)
'parameters
Dim cmd As New SqlCommand("putpending", scn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@cuuser", SqlDbType.NVarChar, 1000)
cmd.Parameters("@cuuser").Value = user
cmd.Parameters.Add("@iuser", SqlDbType.NVarChar, 1000)
cmd.Parameters("@iuser").Value = intenduser
'execute
scn.Open()

cmd.ExecuteNonQuery()

scn.Close()
//END

Any ideas why i am getting this error message?

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 08/31/2006 :  06:51:26  Show Profile  Visit SwePeso's Homepage  Reply with Quote
What is pending keyword?

Also rewrite your dynamic sql as
SELECT @sql = 
'INSERT INTO ' +
@cuuser + 
' (Pending) VALUES (' + @iuser + ')'

EXECUTE (@sql)

Peter Larsson
Helsingborg, Sweden

Edited by - SwePeso on 08/31/2006 06:52:28
Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5528 Posts

Posted - 08/31/2006 :  06:52:51  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
ALTER PROCEDURE [dbo].[putpending]
(@cuuser nvarchar(1000), @iuser nvarchar(1000))

AS
Declare @sql nvarchar(1000)

SELECT @sql = 
'INSERT INTO ' +
@cuuser + 
' (Pending) VALUES (''' + @iuser + ''')'

EXECUTE (@sql)

RETURN


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 08/31/2006 :  06:55:20  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Finally





Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5528 Posts

Posted - 08/31/2006 :  07:01:15  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
quote:
Originally posted by Peso

What is pending keyword?



Peso,
I believe Pending is the column name, not a keyword !!

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

magnetica
Starting Member

36 Posts

Posted - 08/31/2006 :  07:01:31  Show Profile  Click to see magnetica's MSN Messenger address  Reply with Quote
Perfect!!
Cheers people, always something silly isnt it! lol
Oh and Pending is simply a column name within my table
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 08/31/2006 :  07:05:51  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Ah! Now I see it too.
All this dynamic SQL makes me dizzy

Thanks, Harsh.


Peter Larsson
Helsingborg, Sweden

Edited by - SwePeso on 08/31/2006 07:06:57
Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5528 Posts

Posted - 08/31/2006 :  07:55:14  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
quote:
Originally posted by Peso
All this dynamic SQL makes me dizzy



me too!

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 08/31/2006 :  08:36:32  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
Why is the table to insert into a parameter ?



- Jeff
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 08/31/2006 :  08:42:59  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Because normalization is not heard of?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 08/31/2006 :  12:05:07  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by Peso

Finally





Peter Larsson
Helsingborg, Sweden


Yes Finally you got it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000