Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim product_code As String = product.SelectedItem.Value
Dim price As Decimal = txt_price.Text
Dim unit As Decimal = txt_NumProduct.Text
Dim PriceIncludes As Decimal = price * unit
Dim dis As String = Calculate(product_code, PriceIncludes, unit)
Dim total As Decimal = PriceIncludes - dis
price = (Math.Truncate(price * 100)) / 100
If IsNumeric(txt_price.Text) Then
TextBox2.Text = ("" & PriceIncludes)
TextBox3.Text = (" " & dis)
TextBox4.Text = (" " & total)
End If
End Sub
Function Calculate(ByVal product_code As String, ByVal PriceIncludes As Decimal, ByVal Unit As Decimal) As Decimal
Dim dis As Decimal = 0
Dim dt As New DataTable
Dim sqlconn As New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Dim reader As OleDbDataReader
Dim comm As New StringBuilder
comm.Append(" select discount ")
comm.Append(" from promotion ")
comm.Append(" where product = ? ")
comm.Append(" and ( ( minmax_type_id = '2' and ((min_price <= ? ) and (isnull(max_price,9999999 ) >= ?)))")
comm.Append(" or( minmax_type_id = '1' and ((min_price <= ? ) and (isnull(max_price,9999999 ) >= ?)) ) ) ")
Dim OleComm As New OleDbCommand(comm.ToString, sqlconn)
OleComm.Parameters.AddWithValue("@00", product_code)
OleComm.Parameters.AddWithValue("@01", PriceIncludes)
OleComm.Parameters.AddWithValue("@02", PriceIncludes)
OleComm.Parameters.AddWithValue("@03", Unit)
OleComm.Parameters.AddWithValue("@04", Unit)
sqlconn.Open()
reader = OleComm.ExecuteReader(CommandBehavior.CloseConnection)
If reader.HasRows Then
dt.Load(reader)
dis = dt.Rows(0).Item("discount")
End If
'Dim a As New Page4
'a.MinMax()
Return dis
End Function
Error message : Additional information: Command text was not set for the command object.
Tag : .NET, Web (ASP.NET), VB.NET, VS 2013 (.NET 4.x)