Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to insert totalprice value to access database

how to insert totalprice value to access database

Scheduled Pinned Locked Moved ASP.NET
databasetutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blurMember
    wrote on last edited by
    #1

    im using vb. To summarize, i have a textbox where user input quantity and a gridview to display the price. i also have a submit button to calculate the totalprice where totalprice = quantity * price. meanwhile im using a label to store the value price. Dim tmp As Double = e.Row.Cells(3).Text.Trim Label1.Text = "$" + (tmp).ToString("0.00") this is the submit coding myCommand.CommandText = "INSERT INTO [Order] ([Quantity], [TotalPrice]) VALUES ('" & CStr(Me.txtQty.Text) & "',__________)" is ________ me.txtQty * Label.Text ?? i need to know what should be the correct way.

    thanks in advance. Much appreciated.

    P 1 Reply Last reply
    0
    • B blurMember

      im using vb. To summarize, i have a textbox where user input quantity and a gridview to display the price. i also have a submit button to calculate the totalprice where totalprice = quantity * price. meanwhile im using a label to store the value price. Dim tmp As Double = e.Row.Cells(3).Text.Trim Label1.Text = "$" + (tmp).ToString("0.00") this is the submit coding myCommand.CommandText = "INSERT INTO [Order] ([Quantity], [TotalPrice]) VALUES ('" & CStr(Me.txtQty.Text) & "',__________)" is ________ me.txtQty * Label.Text ?? i need to know what should be the correct way.

      thanks in advance. Much appreciated.

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      Plz try this cdbl(me.txtQty.text) * cdbl(Label.Text ) or cint(me.txtqty.text) * cint(Lable.Text) Your access database column type should be integer, Float or Double.... Quantity,TotalPrice. Better way......... dim Total as integer = cint(me.txtqty.text) * cint(Lable.Text) "Insert Into order (quantity,TotalPrice) Values (" & me.txtQty.Text & "," & cstr(Total) & ")"

      Parwej Back...............DON of Developer....... Parwej Ahamad g_parwez@rediffmail.com

      B 1 Reply Last reply
      0
      • P Parwej Ahamad

        Plz try this cdbl(me.txtQty.text) * cdbl(Label.Text ) or cint(me.txtqty.text) * cint(Lable.Text) Your access database column type should be integer, Float or Double.... Quantity,TotalPrice. Better way......... dim Total as integer = cint(me.txtqty.text) * cint(Lable.Text) "Insert Into order (quantity,TotalPrice) Values (" & me.txtQty.Text & "," & cstr(Total) & ")"

        Parwej Back...............DON of Developer....... Parwej Ahamad g_parwez@rediffmail.com

        B Offline
        B Offline
        blurMember
        wrote on last edited by
        #3

        thanks but there was an error No value given for one or more required parameters. Dim Total As Integer = CInt(Me.txtQty.Text) * CInt(Label1.Text) myCommand.CommandText = "INSERT INTO [Ord] ([Quantity], [TotalPrice]) VALUES ('" & CStr(0) & "','" & CStr(Total) & "')" i change my databse for TotalPrice to number instead of currency.

        thanks in advance. Much appreciated.

        G 1 Reply Last reply
        0
        • B blurMember

          thanks but there was an error No value given for one or more required parameters. Dim Total As Integer = CInt(Me.txtQty.Text) * CInt(Label1.Text) myCommand.CommandText = "INSERT INTO [Ord] ([Quantity], [TotalPrice]) VALUES ('" & CStr(0) & "','" & CStr(Total) & "')" i change my databse for TotalPrice to number instead of currency.

          thanks in advance. Much appreciated.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          The error message means that you have one or more names in the query that doesn't match the database. Check the name of the table and the names of the fields. If the fields are numeric, you should not use apostrophes around the values, as that makes them string values. Why are you storing the total price in the database anyway? If you display the data later, don't you want to display both the price and the total price? You can always calculate the total price if you store the price and the quantity, but if you store the total price and quantity you have to re-create the price, which is a bit backwards.

          --- Year happy = new Year(2007);

          B 1 Reply Last reply
          0
          • G Guffa

            The error message means that you have one or more names in the query that doesn't match the database. Check the name of the table and the names of the fields. If the fields are numeric, you should not use apostrophes around the values, as that makes them string values. Why are you storing the total price in the database anyway? If you display the data later, don't you want to display both the price and the total price? You can always calculate the total price if you store the price and the quantity, but if you store the total price and quantity you have to re-create the price, which is a bit backwards.

            --- Year happy = new Year(2007);

            B Offline
            B Offline
            blurMember
            wrote on last edited by
            #5

            in detail, i have two tables, 1 is products details and the other is order details. so the totalprice n quantity are meant for the order details table. so how should i solve the problem? both the field names are spelled correctly.

            thanks in advance. Much appreciated.

            G 1 Reply Last reply
            0
            • B blurMember

              in detail, i have two tables, 1 is products details and the other is order details. so the totalprice n quantity are meant for the order details table. so how should i solve the problem? both the field names are spelled correctly.

              thanks in advance. Much appreciated.

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              blurMember wrote:

              in detail, i have two tables, 1 is products details and the other is order details. so the totalprice n quantity are meant for the order details table.

              I see. You might consider copying the price from the products table to the order table at the time of the order, so that the orders doesn't change if the product changes.

              blurMember wrote:

              both the field names are spelled correctly.

              The database begs to differ... ;) Debug the application and look at the query that you created, so that you see if it ended up the way that you expect.

              --- Year happy = new Year(2007);

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups