Can't Display the total values in textbox
I can see the oddity here, you are setting text for txtCartItems
, after you are doing Response.Write
, and that does reload your page before, even you set value if txtCartItems
. So you can use following code to set the value and then do reload
Dim productQuantity As Integer
Dim totalPrice As Integer
Integer.TryParse(txtQuantity.Text, productQuantity)
totalPrice = productQuantity * Val(txtSellingPrice.Text)
'establish the first connection
con = New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source = " & Server.MapPath("Erika_Kyl_PointOfSales.mdb"))
con.Open()
query2 = "INSERT INTO tbl_Orders(product_name,product_category,product_quantity,total_price) VALUES('" & txtProductName.Text & "','" & txtCategory.Text & "','" & productQuantity & "','" & totalPrice & "')"
cmd = New OleDb.OleDbCommand(query2, con)
cmd.ExecuteNonQuery()
cmd.Dispose()
con.Close()
'establish the second connection
con = New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source = " & Server.MapPath("Erika_Kyl_PointOfSales.mdb"))
con.Open()
query3 = "SELECT COUNT(*) AS totalOrders FROM tbl_Orders"
cmd = New OleDb.OleDbCommand(query3, con)
dr = cmd.ExecuteReader()
While dr.Read()
txtCartItems.Text = dr("totalOrders").ToString()
End While
'align the value of textbox in center
txtCartItems.Style("text-align") = "center"
cmd.Dispose()
con.Close()
'clear the items in the textbox after adding them to tbl_Orders
txtISBN.Text = ""
txtProductName.Text = ""
txtCategory.Text = ""
txtQuantity.Text = ""
txtSellingPrice.Text = ""
Response.Write(<script>alert('Orders Successfully Added!')</script>)
Response.Write("<script>window.location.reload()</script>")
Related videos on Youtube
doria_aries
Updated on November 27, 2022Comments
-
doria_aries over 1 year
I have a program that counts the total values in the database and inserts the total values in a textbox named, txtCartItems.Text. The problem that I am encountering, is that whenever I add the Response.Write() code blocks, It displays the values that I inserted in the table, but it does not put the total values that I inserted in the txtCartItems.Text. And when I remove the Response.Write() code blocks, it displays the counted values in the txtCartItems.Text but I can't view the values that I recently added in the table. All I want is that, whenever I search for an item and add it, I can simultaneously view the values in the table and the total number of values that I inserted in the txtCartItems.Text.
Dim productQuantity As Integer Dim totalPrice As Integer Integer.TryParse(txtQuantity.Text, productQuantity) totalPrice = productQuantity * Val(txtSellingPrice.Text) 'establish the first connection con = New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source = " & Server.MapPath("Erika_Kyl_PointOfSales.mdb")) con.Open() query2 = "INSERT INTO tbl_Orders(product_name,product_category,product_quantity,total_price) VALUES('" & txtProductName.Text & "','" & txtCategory.Text & "','" & productQuantity & "','" & totalPrice & "')" cmd = New OleDb.OleDbCommand(query2, con) cmd.ExecuteNonQuery() cmd.Dispose() con.Close() Response.Write(<script>alert('Orders Successfully Added!')</script>) Response.Write("<script>window.location.reload()</script>") 'establish the second connection con = New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source = " & Server.MapPath("Erika_Kyl_PointOfSales.mdb")) con.Open() query3 = "SELECT COUNT(*) AS totalOrders FROM tbl_Orders" cmd = New OleDb.OleDbCommand(query3, con) dr = cmd.ExecuteReader() While dr.Read() txtCartItems.Text = dr("totalOrders").ToString() End While 'align the value of textbox in center txtCartItems.Style("text-align") = "center" cmd.Dispose() con.Close() 'clear the items in the textbox after adding them to tbl_Orders txtISBN.Text = "" txtProductName.Text = "" txtCategory.Text = "" txtQuantity.Text = "" txtSellingPrice.Text = ""
-
Arindam Nayak over 9 yearsStill i am not clear, however, as a suggestion, you can use
If dr.Read()
, as this will be having single values only (count(*)
), instead of doing it withwhile
-
doria_aries over 9 yearsAll I want is that whenever I search for an item and add it, it automatically adds to the table and i can see the total values in the table in the txtCartItems.Text.
-
Arindam Nayak over 9 yearsWhy do you need
Response.Write
and if it reloads , does that page_load sets the value intxtCartItems
? -
Arindam Nayak over 9 yearsDoes this
Reload
in javascript , does all of thing, i mean it will reload the page and insert into DB and then set value intxtCartItems
?
-