Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 7th, 2003, 07:11 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: Halifax, Nova Scotia, Canada.
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using an insert stored procedure

If I have an insert stored proc. already writen. How do I use it in VB, asuming the DB is already connected to. I have text boxes full of info and I want to click an insert command button and insert a new record in the DB. I know there is a way by using the execute SQL command but I am not sure of the syntax. I don't want to set up a parameters storedproc I just want to use the storedproc I already have. I hope I explained it right.

Thanks for you help

Jamie

__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
Reply With Quote
  #2 (permalink)  
Old August 7th, 2003, 08:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: McPherson, Kansas, USA.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Didn't just post this message yesterday?

Anyway, If you are going to use a stored procedure or any other method to update\insert data into a data table then you are going to have to use parameters. Think about it.

You have a text box that may contain the name of a new user. You want to add the users name to the user name table in your database. You also have this nice stored procedure that will handle the insert. If you do not pass the stored procedure any parameters, like the users name, what will it insert into the database. Somehow you have to pass the user name to the stored procedure. That would be a neat trick if you could do it without giving it the user name.

You can also use the execute method provided by your connection object but then you have to re-write your sql statement and your stored procedure will never run. But, again you still need to provide the user name, simply put this is a parameter.

So I am going to provide the same reply and see if it makes more sense.

' Create a command object
Dim Cmd as New Adodb.Command
' Set the command object equal to the connection object
Set Cmd.ActiveConnection = Cn
' Define the Store procedure
With Cmd
     .CommandText = "sp_YourSprocsName"
     .CommandType = adCmdStoredProc
     ' Set parameters
     ' Substitute "@MyParam1" with the name of any parameters
     ' required by the sproc
     ' Substitute Value1 with the parameter value
     .Parameter("@MyParam1") = Value1
     ' Repeat this for each parameter
     .Parameter("@MyParamX") = ValueX
     ' Execute the stored procedure
     ' If you are not returning records then
     .Execute
     ' If you are returning records and assuming
     ' your recordset object is named rs
     Set rs = .Execute()
     ' You can now reference your recordset object as usual
End With


Please ask me if you do not understand this and I will try to answer your question and explain it better. If you need further help try posting your stored procedure then maybe we can give you a more explicit answer.


Larry Asher
Reply With Quote
  #3 (permalink)  
Old August 7th, 2003, 08:38 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: Halifax, Nova Scotia, Canada.
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used your post from yesterday and with today's info it really helped. Thanks for your help I wasn't understanding it completly. I have the paramters all set up and it seems to be working right now.
Thanks again for your help.

Reply With Quote
  #4 (permalink)  
Old August 7th, 2003, 08:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: McPherson, Kansas, USA.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Glad I could help. Hope your project is going well as a whole.

Larry Asher
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check value while insert in stored procedure Andraw SQL Server 2005 2 August 12th, 2008 09:08 AM
insert using stored procedure & sqldatasource ctrl mahajanvit ASP.NET 2.0 Basics 10 September 13th, 2006 09:03 AM
Stored Procedure Insert Null Value harpua SQL Server ASP 2 March 5th, 2005 10:19 AM
stored procedure dynamic insert harpua Classic ASP Databases 3 January 21st, 2005 12:50 AM
How do I insert stored procedure through C# nishim.attreja VB How-To 1 September 18th, 2004 01:24 AM



All times are GMT -4. The time now is 01:20 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.