Tuesday, March 13, 2012

Stuck again

Hi Guys

Here is my problem

I have a sql database with a field voucherRate(int4) that contains a figure that will be used to create a discount.

Here is my code so far


'Declare the discount string
dim strDiscount as double
'declare the total string
dim strTotal as double = 10
Sub Page_Load
'set up connection to db
Dim conNorthwind As SqlConnection
Dim dsEmployees As DataSet
dsEmployees = New Dataset

' Retrieve records from database
conNorthwind = New SqlConnection( "server=(local);uid=sa;pwd=*****;database=dbSQL" )
Dim daEmployees As SQLDataAdapter
daEmployees = New SqlDataAdapter( "Select voucherRate from vouchers", conNorthwind )
daEmployees.Fill( dsEmployees, "voucherRate" )

conNorthwind.Close()
strDiscount = daEmployees( "VoucherRate" )
End Sub

OK what I need to add but am really struggling with is this;
strDiscount = "DataSet Voucher Rate" / 100 * strTotal

What would be the correct syntax for creating this stringFirst of all...
I find your variable names very different...
I am not sure why you have "str" before all your variables...
Check out MSDN site for naming convention...

Anyhow...
here's the code to access your voucherRate field...


conNorthwind.close()

strDiscount = CType(dsEmployees.Tables(0).Rows(0).Item("voucherRate"),Integer)/100 * strTotal

But please note that your dataset might have more than one records and hence you have to loop through the dataset to calculate discount for all the records...

0 comments:

Post a Comment