473,960 Members | 38,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert stored procedure

Could someone tell me how to implement an INSERT on an aspx-page using a
stored procedure, in VB-code?

THX,
Nic

PS: I have been trying this, but it ain't working:

Sub insert_new_cont ent (sender As Object, e As EventArgs)

Dim MyConnectionStr ing as String =
ConfigurationSe ttings.AppSetti ngs("Connection String")
Dim myConnection As SQLConnection
myConnection = New SQLConnection(M yConnectionStri ng)

Dim myCommand As New SqlCommand("spa ddshopscats", myConnection)
myCommand.Comma ndType = CommandType.Sto redProcedure
Dim Parameter As SqlParameter

Parameter = New SqlParameter("@ shopID", SqlDbType.Int, 4)
myCommand.Param eters.Add(Param eter)
Parameter.Direc tion = ParameterDirect ion.Input
Parameter.Value = ctype(request.q uerystring("sho pID"),integer)

Parameter = New SqlParameter("@ categoryID", SqlDbType.VarCh ar, 2000)
myCommand.Param eters.Add(Param eter)
Parameter.Direc tion = ParameterDirect ion.Input
Parameter.Value = categoryID.text
myConnection.Op en()
myCommand.Execu teNonQuery()

myConnection.Cl ose()

End Sub
Nov 18 '05 #1
4 1528
What error are you getting?
"nicholas" <mu********@hot mail.com> wrote in message
news:OC******** ******@TK2MSFTN GP12.phx.gbl...
Could someone tell me how to implement an INSERT on an aspx-page using a
stored procedure, in VB-code?

THX,
Nic

PS: I have been trying this, but it ain't working:

Sub insert_new_cont ent (sender As Object, e As EventArgs)

Dim MyConnectionStr ing as String =
ConfigurationSe ttings.AppSetti ngs("Connection String")
Dim myConnection As SQLConnection
myConnection = New SQLConnection(M yConnectionStri ng)

Dim myCommand As New SqlCommand("spa ddshopscats", myConnection)
myCommand.Comma ndType = CommandType.Sto redProcedure
Dim Parameter As SqlParameter

Parameter = New SqlParameter("@ shopID", SqlDbType.Int, 4)
myCommand.Param eters.Add(Param eter)
Parameter.Direc tion = ParameterDirect ion.Input
Parameter.Value = ctype(request.q uerystring("sho pID"),integer)

Parameter = New SqlParameter("@ categoryID", SqlDbType.VarCh ar, 2000)
myCommand.Param eters.Add(Param eter)
Parameter.Direc tion = ParameterDirect ion.Input
Parameter.Value = categoryID.text
myConnection.Op en()
myCommand.Execu teNonQuery()

myConnection.Cl ose()

End Sub

Nov 18 '05 #2
The problem was in my stored procedure: in my second line I had "@categoryI D
varchar (200)" => I removed "(200)" and it works now. But it is still not
working perfectly:

This is the stored procedure:
---------
CREATE PROCEDURE spaddshopscats

@shopID int, @categoryID varchar

AS

DECLARE @CatInsert varchar(2000)

SET @CatInsert = 'INSERT INTO tbl_shopscats (shopID, categoryID) SELECT ' +
CONVERT(varchar ,@shopID) + ', categoryID From tbl_categories Where
categoryID IN (' + @categoryID + ')'

exec (@CatInsert)

Return
GO
-----------

So, in @categoryID there is a string of category ID's separated by comma's
(ex: 1,25,78)
The stored procedure should insert for each of these values a new record
together with the id of the shop.

So if @shopID = 63

We should have these records inserted:
record1: shopID= 63 and categoryID=1
record2: shopID= 63 and categoryID=25
record3: shopID= 63 and categoryID=78
Now, it works for the categoryID = 1 but not for the others.

THX for your help,
Nic

"Nick Stansbury" <ni************ @sage-removepartners. com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
What error are you getting?
"nicholas" <mu********@hot mail.com> wrote in message
news:OC******** ******@TK2MSFTN GP12.phx.gbl...
Could someone tell me how to implement an INSERT on an aspx-page using a
stored procedure, in VB-code?

THX,
Nic

PS: I have been trying this, but it ain't working:

Sub insert_new_cont ent (sender As Object, e As EventArgs)

Dim MyConnectionStr ing as String =
ConfigurationSe ttings.AppSetti ngs("Connection String")
Dim myConnection As SQLConnection
myConnection = New SQLConnection(M yConnectionStri ng)

Dim myCommand As New SqlCommand("spa ddshopscats", myConnection)
myCommand.Comma ndType = CommandType.Sto redProcedure
Dim Parameter As SqlParameter

Parameter = New SqlParameter("@ shopID", SqlDbType.Int, 4)
myCommand.Param eters.Add(Param eter)
Parameter.Direc tion = ParameterDirect ion.Input
Parameter.Value = ctype(request.q uerystring("sho pID"),integer)

Parameter = New SqlParameter("@ categoryID", SqlDbType.VarCh ar, 2000)
myCommand.Param eters.Add(Param eter)
Parameter.Direc tion = ParameterDirect ion.Input
Parameter.Value = categoryID.text
myConnection.Op en()
myCommand.Execu teNonQuery()

myConnection.Cl ose()

End Sub


Nov 18 '05 #3
I can't see straight away why your code isn't working.

However your approach isn't ideal. From a performance perspective you're not
gaining much by doing this all in one go - from what I've read its opening
and closing the database connection that has the overhead. I'd adjust like
this:

Create Procedure spAddShopsCats
@ShopId int,
@CategoryId int
as

insert into tbl_shopsCats (ShopID, categoryID) VALUES (@ShopID, @CategoryID)

Then just exec the procedure once per category rather than try and get the
stored procedure to parse the string. If you really do want to do it all in
one go then post DDL (create table script etc.) and I'll have a longer look.
CREATE PROCEDURE spaddshopscats

@shopID int, @categoryID varchar

AS

DECLARE @CatInsert varchar(2000)

SET @CatInsert = 'INSERT INTO tbl_shopscats (shopID, categoryID) SELECT ' + CONVERT(varchar ,@shopID) + ', categoryID From tbl_categories Where
categoryID IN (' + @categoryID + ')'

exec (@CatInsert)

Return
GO
-----------

So, in @categoryID there is a string of category ID's separated by comma's
(ex: 1,25,78)
The stored procedure should insert for each of these values a new record
together with the id of the shop.

So if @shopID = 63

We should have these records inserted:
record1: shopID= 63 and categoryID=1
record2: shopID= 63 and categoryID=25
record3: shopID= 63 and categoryID=78
Now, it works for the categoryID = 1 but not for the others.

Nov 18 '05 #4
Thanks for your help, but I changed my code completely.
Is better and safer and most important: it works !

Thanks a lot,
Nic

"Nick Stansbury" <ni************ @sage-removepartners. com> wrote in message
news:em******** ******@tk2msftn gp13.phx.gbl...
I can't see straight away why your code isn't working.

However your approach isn't ideal. From a performance perspective you're not gaining much by doing this all in one go - from what I've read its opening
and closing the database connection that has the overhead. I'd adjust like
this:

Create Procedure spAddShopsCats
@ShopId int,
@CategoryId int
as

insert into tbl_shopsCats (ShopID, categoryID) VALUES (@ShopID, @CategoryID)
Then just exec the procedure once per category rather than try and get the
stored procedure to parse the string. If you really do want to do it all in one go then post DDL (create table script etc.) and I'll have a longer look.

CREATE PROCEDURE spaddshopscats

@shopID int, @categoryID varchar

AS

DECLARE @CatInsert varchar(2000)

SET @CatInsert = 'INSERT INTO tbl_shopscats (shopID, categoryID) SELECT '
+
CONVERT(varchar ,@shopID) + ', categoryID From tbl_categories Where
categoryID IN (' + @categoryID + ')'

exec (@CatInsert)

Return
GO
-----------

So, in @categoryID there is a string of category ID's separated by

comma's (ex: 1,25,78)
The stored procedure should insert for each of these values a new record
together with the id of the shop.

So if @shopID = 63

We should have these records inserted:
record1: shopID= 63 and categoryID=1
record2: shopID= 63 and categoryID=25
record3: shopID= 63 and categoryID=78
Now, it works for the categoryID = 1 but not for the others.


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9023
by: Bill Kellaway | last post by:
Hi there - this should be fairly simple for someone. Basically I can't figure out how to pass the parameters from ASP to a Stored Procedure on SQL. Here's my code: I just need to help in learning how to pass these varibables from ASP to the SP.
1
8353
by: Harald | last post by:
Hi, is it possible to create an "INSERT INTO ..... "Select from stored procedure" Query? I want to create an temporary table. In this table I want to enter the data, which I can get from an stored procedure. But in the FROM-clause a stored procedure is not allowed?
2
3346
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have several stored procedures to Insert and update datas in our SQL database. Some stored procedures are smaller (insert datas in only one table) and some of them are quite big (insert datas in several
6
2089
by: Lelle | last post by:
Hello ! how can i insert text containg code examples from a textbox into a database using SQL insert statment. i have no problem to just add text that dont contains code and script examples or the illegal chars for the insert command is it possible to encasulate the text/string so the server doesnt reads the string as a command?
0
3762
by: Scarab | last post by:
Hi all, When I use following sql to get data in stored procedure, error occurs: insert into #tmp EXECUTE dbo.prc_1 @date1,@date1 Here is the source code, Thanks CREATE TABLE ( NULL , NULL ) ON
6
2374
by: SandySears | last post by:
I am trying to use a stored procedure to insert a record using VS 2005, VB and SQL Server Express. The code runs without errors or exceptions, and returns the new identifer in the output parameters. It returns my error text message in another output parameter as "ok", which is the value that is set in the stored procedure prior to doing the insert. It returns my var for @@rowcount as 1. However, the record does not get into the table. ...
6
9920
by: Peter Neumaier | last post by:
Hi, I am trying to select some data through a stored procedure and would like to store the result in a local access table. Is that possible? Can somebody provide an example? Thanks&regards! Peter
1
6146
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
6
6292
by: pretzla | last post by:
I have a PL/SQL script where I load data from a stored procedure into bind variables. Then, I insert that data from the bind variables into an Oracle table with a simple insert statement. The execution of the stored procedure and the insert are in a FOR-LOOP. insert into ccd_t (acct_id, acct_seq_no, acct_btn) values
0
10265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11710
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10797
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10004
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8374
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
5067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3664
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.