Using Data Binding vs SqlCommand - C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sampalmer21
    New Member
    • Feb 2008
    • 11

    Using Data Binding vs SqlCommand - C#

    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_FormatC urrency(object sender, ConvertEventArg s 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?
  • maheshmrk22
    New Member
    • Dec 2007
    • 23

    #2
    Hi,

    I think the databinding is optimal way to use. Even the sql query method also gives you output that you want but I always used to handle everything in my code. So I suggest you the databinding method.

    Thanks
    Mahesh

    Comment

    Working...