Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,664 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,059 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



STORED PROCEDURES?

 
Reply to this topicStart new topic

STORED PROCEDURES?, I dont know how

sattua
post 1 Aug, 2008 - 02:55 PM
Post #1


New D.I.C Head

*
Joined: 20 Mar, 2008
Posts: 25


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

Go to the top of the page


PsychoCoder
post 1 Aug, 2008 - 08:48 PM
Post #2


DIC.Rules == true;

Group Icon
Joined: 26 Jul, 2007
Posts: 7,142



Thanked 50 times

Dream Kudos: 7700

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, GDI

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 online!Profile CardPM

Go to the top of the page

sattua
post 2 Aug, 2008 - 06:13 PM
Post #3


New D.I.C Head

*
Joined: 20 Mar, 2008
Posts: 25


My Contributions


thank you very much psychocoder......
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 3 Aug, 2008 - 12:27 AM
Post #4


DIC.Rules == true;

Group Icon
Joined: 26 Jul, 2007
Posts: 7,142



Thanked 50 times

Dream Kudos: 7700

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, GDI

My Contributions


No problem, glad I could help smile.gif
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 10:37PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month