Hi,
I'm creating a database application using c# and ado.net with winforms controls. In sql there is a data type called money which stores values in the format xx.xxxx, this is not in the typical currency fashion of $xx.xx, therefore I use the following sql command and ADO.NET's DataReader class to convert the sql money format to a currency format before displaying it on a textbox control:
SELECT
Qty,
'$' + CONVERT(varchar(12), Price, 1) AS Price,
'$' + CONVERT(varchar(12), Qty * Price, 1) AS Total
FROM [Orders]
But I just learned that you could use data binding with the Format Event handler in the Binding class to format the xx.xxxx data to $xx.xx just before it is displayed on the textbox instead of having to use the sql command mentioned above. Thus I would use the code below to handle the format event:
private void textBox_FormatCurrency(object sender, ConvertEventArgs e)
{
e.Value = (double) e.Value;
}
So I'm wondering which is the optimal method to use, either the sql command way or the data binding way?