0

With regards to another thread, http://www.daniweb.com/forums/thread251069.html on how to compare the current date to retrieve relevant data (Details there), now I have issue on storing this query result on a VB.net variable.

It works in this way. It is an academic work to do a ecommerce website, and I need to compute some tax imposed on the goods purchased. Relevant subtotal etc has been implemented except on computing the tax. It is supposed to be a function and I have coded it in this way:

Public Function computeTaxCharge(ByVal dblSubTotal As Double) As Double
        Dim dblTaxRate As Double
        Dim dblTaxCharge As Double

        Dim strConn As String
        strConn = ConfigurationManager.ConnectionStrings("AppDb").ToString
        Dim conn As New SqlConnection(strConn)
            Dim strSql As String
            strSql = "SELECT Top 1 TaxRate" & _
            "FROM GST" & _
            "WHERE EffectiveDate <= @dt" & _
            "ORDER BY EffectiveDate DESC"
            ' Define an Command object to execute the SQL statement
            Dim cmd1 As New SqlCommand(strSql, conn)
            cmd1.Parameters.AddWithValue("@Dt", System.DateTime.Now())
            ' Open database connection
            conn.Open()
            ' Execute the Insert SQL
            cmd1.ExecuteNonQuery()
          
            ' Define a data adapter to fetch data
            Dim da As New SqlDataAdapter(cmd1)
            'Create a dataset
            Dim ds As New DataSet
            ' Fetch data to a table
            da.Fill(ds, "dblTaxRate")
            ' Define a data table to hold the data fetched
            Dim dt As New DataTable
            ' Close database connection
            conn.Close()
            dblTaxCharge = dblSubTotal * dblTaxRate / 100
            Return dblTaxCharge
    End Function

But it crashes on

da.Fill(ds,"dblTaxRate")

.

How should I do? Thank you in advance.

1
Contributor
1
Reply
8
Views
7 Years
Discussion Span
Last Post by samuel_1991
0

Ok, I will make it clear.


I need to use a query to fetch data from database.
The query result must assign to a variable, dblTaxrate that will do the computing in computeTaxCharge using

dblTaxCharge = dblSubtotal * dblTaxrate / 100

where dblTaxCharge is something to show the tax charged on a label during initalization. (This has implemented)

Thus, in short, that is I wish to save my query result on to dblTaxRate which is currently not part of any dataTable, label, textbox etc.

Edited by samuel_1991: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.