Also, I can call that function, GetTotalAmount(), from any other Web Form,
usually in the code behind file. ex:
default.aspx - presentation file, HTML, etc...
default.aspx.vb - code behind
You just have to prefix the function name with the Class name, in this
example is ShoppingCart . . . so ShoppingCart.GetTotalAmoun
Main Topics
Browse All Topics





by: MikeMCSDPosted on 2004-11-02 at 15:33:30ID: 12478862
First, make a Class file (.vb) and put your function in there, ex:
ring) ", connection) e artID", SqlDbType.Char, 36) D").Value = shoppingCartId
t()
ShoppingCart.vb :
Public Class ShoppingCart
Public Shared Function GetTotalAmount() As Decimal
Dim connection As New SqlConnection(connectionSt
Dim command As SqlCommand = New SqlCommand("GetTotalAmount
command.CommandType = CommandType.StoredProcedur
command.Parameters.Add("@C
command.Parameters("@CartI
' The amount has a default value of 0
Dim amount As Decimal = 0
Try
' Try to get the amount from the database
connection.Open()
amount = command.ExecuteScalar()
Finally
connection.Close()
End Try
Return amount
End Function
End Class
Then, in this example, I'm calling the function from the ShoppingCart.aspx.vb
code behind file:
Dim amount As Decimal = ShoppingCart.GetTotalAmoun
totalAmountLabel.Text = String.Format("{0:c}", amount)
I'll post another example if you want.