Difficulty uploading information to database

  • Thread starter martinharvey via DotNetMonster.com
  • Start date
M

martinharvey via DotNetMonster.com

This is probably a very simple question but i am having problems with
inserting information into database

The function takes the values "FirstName" And "LastName" from a table Called

"Customer" and the value "ProductID" from a table called "Products" and
inserts them into a table called " NewOrder".

Everything compiles ok but when I press the button the information is not
uploaded to the
database. ( There is no error message)

This is the stored procedure

CREATE PROCEDURE SP_NewOrder
(@CartID char (36), @CustomerID Varchar (50))
AS

INSERT INTO NewOrder (FirstName, LastName, ProductID)

SELECT Customer.FirstName, Customer.LastName, Products.ProductID

From Customer,Products Join ShoppingCart ON Products.ProductID =ShoppingCart.
ProductID
WHERE ShoppingCart.CartID = @CartID AND Customer.CustomerID = @CustomerID
GO

This is the Function

Public Shared Function CreateOrder() AS String
Dim customerID As integer
Dim connection as New SqlConnection(connectionString)
Dim command as New SqlCommand("SP_NewOrder",connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@CartID", SqlDbType.Char,36)
command.Parameters("@CartID").Value = shoppingCartID
command.Parameters.Add("@CustomerID", SqlDbType.Varchar,36)
command.Parameters("@CustomerID").Value = customerID
Try

connection.Open()
command.ExecuteNonQuery()
Finally
connection.Close()

End Try
End Function

This is the page code

Sub btn3_Click(sender As Object, e As EventArgs)
Dim cart as New ShoppingCart()
Dim shoppingCartID As Integer
Dim customerID As Integer = Context.Session("worldshop_CustomerID")
cart.CreateOrder()
End Sub

Can Anyone see where I am going wrong

Many thanks

martin
 
B

Bruce Barker

you sp does not validate its data, and fails silently. try:



CREATE PROCEDURE SP_NewOrder
(@CartID char (36), @CustomerID Varchar (50))
AS

INSERT INTO NewOrder (FirstName, LastName, ProductID)
SELECT Customer.FirstName, Customer.LastName, Products.ProductID
From Customer,Products
Join ShoppingCart ON Products.ProductID =ShoppingCart.ProductID
WHERE ShoppingCart.CartID = @CartID AND Customer.CustomerID = @CustomerID
if @@rowcount = 0 raiserror('no matching customer/cart combo found',16,1)

GO


-- bruce (sqlwork.com)
 
M

martinharvey via DotNetMonster.com

Bruce said:
you sp does not validate its data, and fails silently. try:

CREATE PROCEDURE SP_NewOrder
(@CartID char (36), @CustomerID Varchar (50))
AS

INSERT INTO NewOrder (FirstName, LastName, ProductID)
SELECT Customer.FirstName, Customer.LastName, Products.ProductID
From Customer,Products
Join ShoppingCart ON Products.ProductID =ShoppingCart.ProductID
WHERE ShoppingCart.CartID = @CartID AND Customer.CustomerID = @CustomerID
if @@rowcount = 0 raiserror('no matching customer/cart combo found',16,1)

GO

-- bruce (sqlwork.com)
This is probably a very simple question but i am having problems with
inserting information into database
[quoted text clipped - 60 lines]

thanks for your help Bruce

I eventually got it to work

many thanks

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top