I am trying to create a simple Exchange Rate converter for our company.
Please find attached code
Function getrate() As System.Data.IDataReader
Dim connectionString As String = "server='(local)\netsdk'; trusted_connection=true; database='Exchange_Rate_Convert"& _
"er'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)Dim queryString As String = "SELECT [Rates].* FROM [Rates]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnectiondbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)Return dataReader
End FunctionSub Page_Load(sender As Object, e As EventArgs)
if not page.ispostback then
rates.datasource = getrate()
rates.databind()rates1.datasource = getrate()
rates1.databind()
end if
End SubSub rates_SelectedIndexChanged(sender As Object, e As EventArgs)
currencytxt.text = " " & rates.selecteditem.text
End Sub
Sub rates1_SelectedIndexChanged(sender As Object, e As EventArgs)
finaltxt.text = ((value_to_convert.text / rates.selecteditem.value) * rates1.selecteditem.value)
End Sub
I have 3 questions:
Question 1:
Everything works as I expected it to if the user uses it once, Enter value -> click on first currency -> click on second currency.
However if they (Perhaps) realized they made a mistake with the first currency click again, then the "Finaltxt.txt value" is not correct.
What I would like to do is to allow as many different button clicks from both sets of Radiobuttonlist's as they care to use and have "Finaltxt.txt value" updated every time a new button is pressed. - I also imagine they may keep the browser open all day and use it perodicaly.
Question 2:
I am not really sure that I should be doing "Maths" from data held in a text box. (I would have assumed this data to be a string, however it does work, I would have thought I would need to convert it in some way but I can't find an appropriate command/syntax.
Question 3:
How do I format the value shown in "Finaltxt.txt value", I would like this figure to be rounded up to two decimal places.
I would appreciate any help given.
Best wishes.
James.perhaps u should have a command button to do the actual conversion
0 comments:
Post a Comment