Welcome to Dream.In.Code
Become an Expert!

Join 150,131 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,148 people online right now. Registration is fast and FREE... Join Now!




STORED PROCEDURES?

 
Reply to this topicStart new topic

STORED PROCEDURES?, I dont know how

sattua
1 Aug, 2008 - 01:55 PM
Post #1

New D.I.C Head
*

Joined: 20 Mar, 2008
Posts: 27


My Contributions
I was triying to use stored procedures that makes an insertion in a table, VB.net show me a Sintaxis error; this is my query:

create procedure myprocedure (in ID int, in NAM varchar(50), in Phone int) begin declare x int; declare y varchar(50); declare z int; set x=ID; set y =NAM;set z = Phone insert into mytable values (x,y,z); end


IT`s for sql server, and I am using VB.net; the Sintaxis error is this:

Syntax incorrect near the keyword 'in'.
'int' is not an option CURSOR recognized.
'varchar' is not an option CURSOR recognized.
'int' is not an option CURSOR recognized.
The name "x" is not valid in this context. The expressions are valid constant, constant expressions and, in some contexts, variables. Are not allowed column names.

thanks....
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: STORED PROCEDURES?
1 Aug, 2008 - 07:48 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Well the syntax you're using is completely wrong. When adding parameters to your stored procedure you don't use the word IN anywhere. Also, you're declaring local variables then setting them to the parameters you declare for your procedure, this is unnecessary and using unneeded resources. Next, parameters for stored procedures need to be prefaced with the @ symbol. Here is how your stored procedure should look


sql

CREATE PROCEDURE MyProcedure @ID INT, @NAM VARCHAR(50),@Phone VARCHAR(15)
AS
INSERT INTO
MyTable
VALUES (@ID, @NAM, @Phone)


That will work if you only have 3 columns in this particular table. If you have more (and are only inserting three values) then you will need to list the columns you're inserting after the table name, like so

sql

CREATE PROCEDURE MyProcedure @ID INT, @NAM VARCHAR(50),@Phone VARCHAR(15)
AS
INSERT INTO
MyTable(Column1, Column2, Column3)
VALUES (@ID, @NAM, @Phone)


Keep in mind that the names Column1, Column2 and Column3 would need to be replaced with the actual names of your columns. Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

sattua
RE: STORED PROCEDURES?
2 Aug, 2008 - 05:13 PM
Post #3

New D.I.C Head
*

Joined: 20 Mar, 2008
Posts: 27


My Contributions
thank you very much psychocoder......
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: STORED PROCEDURES?
2 Aug, 2008 - 11:27 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
No problem, glad I could help smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:47AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month