Difficulty uploading information to database

Discussion in 'ASP .Net' started by martinharvey via DotNetMonster.com, Dec 1, 2005.

  1. 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

    --
    Message posted via DotNetMonster.com
    http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200512/1
    martinharvey via DotNetMonster.com, Dec 1, 2005
    #1
    1. Advertising

  2. martinharvey via DotNetMonster.com

    Bruce Barker Guest

    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)

    "martinharvey via DotNetMonster.com" <u14945@uwe> wrote in message
    news:582d64a1814cc@uwe...
    > 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
    >
    > --
    > Message posted via DotNetMonster.com
    > http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200512/1
    Bruce Barker, Dec 1, 2005
    #2
    1. Advertising

  3. Bruce Barker wrote:
    >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]
    >>
    >> martin


    thanks for your help Bruce

    I eventually got it to work

    many thanks

    martin

    --
    Message posted via DotNetMonster.com
    http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200512/1
    martinharvey via DotNetMonster.com, Dec 2, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bjoern Wolfgardt
    Replies:
    0
    Views:
    436
    Bjoern Wolfgardt
    Jul 16, 2003
  2. Samridhi Kumar Shukla
    Replies:
    1
    Views:
    522
    Alvin Bruney
    Nov 30, 2003
  3. Eric
    Replies:
    0
    Views:
    522
  4. Dung Ping
    Replies:
    10
    Views:
    967
    Chaddy2222
    Jan 16, 2006
  5. yahibble
    Replies:
    1
    Views:
    265
    Grig Gheorghiu
    Jul 21, 2005
Loading...

Share This Page