473,486 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Data Binding vs SqlCommand - C#

11 New Member
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?
Mar 11 '08 #1
1 1946
maheshmrk22
23 New Member
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
Mar 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1890
by: zhaoJian | last post by:
Here it is my code ,but it can't update the database.How to do it ? In _UpdateUnit event, I can not get the original value to @Original_UnitID,so I set a hidden column named LabelKey.But It...
14
5731
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
5
4202
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
1
1677
by: madhu | last post by:
Hello all, I am a bignner to vb.net I am not able to move the dataset and bind the textbox to dataset. My objective is 1) when the form loads it should display the first record. and the...
1
2387
by: Daves | last post by:
a SQL query can return multiple data tables eg SELECT expression1 ... SELECT expression2 ... Can I in ASP.Net utilise this to do fewer data fetches from the server, e.g. selectively binding...
6
5715
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
0
937
by: rang1 | last post by:
Hi, I am trying to create a simple dataentry form that will modify a sequel database table. I am using BindingSource and BindingNavigator to display the data from the table. Then the use would...
1
1283
by: suganya | last post by:
Hi I have "Specialty" table with 2 fields (SPID,Specialty). To bind data from "Specialty: table to the dropdownlist during page load, I have given the following coding protected void...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.