Author |
Topic |
magnetica
Starting Member
36 Posts |
Posted - 2006-08-31 : 06:31:11
|
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??!//BEGINALTER PROCEDURE [dbo].[putpending](@cuuser nvarchar(1000), @iuser nvarchar(1000))ASDeclare @sql nvarchar(1000)SELECT @sql = 'INSERT INTO ' + @cuuser + ' (Pending) VALUES (@iuser)'EXECUTE (@sql)RETURN//ENDAnd 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()//ENDAny ideas why i am getting this error message? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-31 : 06:51:26
|
What is pending keyword?Also rewrite your dynamic sql asSELECT @sql = 'INSERT INTO ' +@cuuser + ' (Pending) VALUES (' + @iuser + ')'EXECUTE (@sql) Peter LarssonHelsingborg, Sweden |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-08-31 : 06:52:51
|
[code]ALTER PROCEDURE [dbo].[putpending](@cuuser nvarchar(1000), @iuser nvarchar(1000))ASDeclare @sql nvarchar(1000)SELECT @sql = 'INSERT INTO ' +@cuuser + ' (Pending) VALUES (''' + @iuser + ''')'EXECUTE (@sql)RETURN[/code]Harsh AthalyeIndia."Nothing is Impossible" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-31 : 06:55:20
|
FinallyPeter LarssonHelsingborg, Sweden |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-08-31 : 07:01:15
|
quote: Originally posted by Peso What is pending keyword?
Peso, I believe Pending is the column name, not a keyword !!Harsh AthalyeIndia."Nothing is Impossible" |
|
|
magnetica
Starting Member
36 Posts |
Posted - 2006-08-31 : 07:01:31
|
Perfect!!Cheers people, always something silly isnt it! lolOh and Pending is simply a column name within my table |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-31 : 07:05:51
|
Ah! Now I see it too.All this dynamic SQL makes me dizzy Thanks, Harsh.Peter LarssonHelsingborg, Sweden |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-08-31 : 07:55:14
|
quote: Originally posted by PesoAll this dynamic SQL makes me dizzy
me too! Harsh AthalyeIndia."Nothing is Impossible" |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-08-31 : 08:36:32
|
Why is the table to insert into a parameter ? - Jeff |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-31 : 08:42:59
|
Because normalization is not heard of?Peter LarssonHelsingborg, Sweden |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-31 : 12:05:07
|
quote: Originally posted by Peso FinallyPeter LarssonHelsingborg, Sweden
Yes Finally you got it MadhivananFailing to plan is Planning to fail |
|
|
|