How to define field attribute for a numeric field in SQL table?

I need create a field to store tax rate.  I need only 2 decimal points.  I defined the field as decimal, precision=5  and scale=2.  Does it mean that it can hold value from 0.00 to 999.99?
0
vljw8202
1/19/2005 7:53:43 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

12 Replies
929 Views

Similar Articles

[PageSpeed] 9

Actually, it should be able to hold from -999.99 through 999.99.

Terri
Terri Morton
Engagement Manager, Neudesic

How to ask a question

0
tmorton
1/19/2005 10:02:56 PM
True... here comes my really problem.   My aspx form always does rounding for me while I update the table.  If I enter 0.7 it will become 0 in the table.  If I enter 2.7 it will become 3 in the table.  What is the trick?
0
vljw8202
1/19/2005 10:28:34 PM
You'll have to show us your code surrounding the SQL command.  It's probably in how your data type is set up in your SQLParameter or something along those lines. There's no trick from a SQL perspective -- a command from Query Analyzer would simply look like this:


UPDATE test SET taxRate = '.7' WHERE ID = 10

Terri
Terri Morton
Engagement Manager, Neudesic

How to ask a question

0
tmorton
1/19/2005 10:38:03 PM
Try Numeric it will make the rounding problem go away in SQL Server, in .NET  search MSDN for Strings and Formating in your language.  Numeric is bigger than Decimal.  Hope this helps.

Kind regards,
Gift Peddie
Kind regards,
Gift Peddie
0
Caddre
1/20/2005 12:13:36 AM
This is how I coded...

First is the class

Namespace BusinessLogicLayer
Public Class Itm
...
Private _PST As Decimal
...
Public Property PST() As Decimal
Get
Return _PST
End Get
Set(ByVal Value As Decimal)
_PST = Value
End Set
End Property
...
...
Public Function Insert() As Boolean
ItmID = Convert.ToInt32(SqlHelper.ExecuteScalar(ConfigurationSettings.AppSettings(Web.Global.CfgKeyConnString), "AddItm", CatID, ItmD1, ItmD2, UOM, UPrice, PSTPcnt, GSTPcnt, Note, MasterItem))
Return ItmID > 0
End Function 'Insert
...
End Class
End Namespace

then page load sub...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
...
If txtPSTPcnt.Text = "" Then
txtPSTPcnt.Text = "0.07"
End If
...
End Sub

then when the Save button is clicked

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
...
Itm.PST = CDec(txtPST.Text)
Itm.Insert()
End Sub

Hopefully you have some clue, thx.
0
vljw8202
1/20/2005 1:07:40 AM
I changed it to numeric and still have the same result.
0
vljw8202
1/20/2005 3:46:39 AM
Sorry I did not get back to you yesterday, you need code in Custom Numeric Format Strings  with using statement from System.globalization.  I found some code using the IFormatProvider and ICustomFormatter interfaces on codeproject site.  The second link is on MSDN Custom Numeric Format Strings Output Examples table you may have to use DOUBLE datatype in .NET.  Hope this helps.

http://www.codeproject.com
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomnumericformatstrings.asp
Kind regards,
Gift Peddie

Kind regards,
Gift Peddie
0
caddre
1/20/2005 9:22:00 PM
Sorry this is the table that show the DOUBLE datatypes human error lol.  Hope this helps

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomnumericformatstringsoutputexample.asp
Kind regards,
Gift Peddie
Kind regards,
Gift Peddie
0
caddre
1/21/2005 10:46:32 PM
Thanks a lot.  you're very helpful.  Since this is my first project on ASP.net and SQL, I can't grap the idea of using the table you refer to.  First of all, where do I define "double" and do I put those code in the ASPX.VB?  Appreciated.
0
vljw8202
1/21/2005 11:35:10 PM
The code below should take you closer to what you want, these are part of the .NET Framework Class Library that perform special tasks for you.  I don't know books that covers it in VB.NET but in C# the Complete Reference by Herbert Schildt covered it in details in C# not Asp.net.  Hope this helps.

NumberFormatInfo.PercentDecimalSeparator Property
[Visual Basic]the effect of changing the PercentDecimalSeparator property.
[Visual Basic]
Imports System
Imports System.Globalization
Class NumberFormatInfoSample
Public Shared Sub Main()
' Gets a NumberFormatInfo associated with the en-US culture.
Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat
' Displays a value with the default separator (".").
Dim myInt As [Double] = 0.1234
Console.WriteLine(myInt.ToString("P", nfi))
' Displays the same value with a blank as the separator.
nfi.PercentDecimalSeparator = " "
Console.WriteLine(myInt.ToString("P", nfi))
End Sub 'Main
End Class 'NumberFormatInfoSample

'This code produces the following output.
'
'12.34 %
'12 34 %
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationnumberformatinfoclasspercentdecimalseparatortopic.asp

Kind regards,
Gift Peddie
Kind regards,
Gift Peddie
0
caddre
1/22/2005 12:19:32 AM
Again thanks for your advice, but I can't find data type Double in SQL2000.  Did I miss something?
0
vljw8202
1/22/2005 2:29:08 AM
Gentlmen, I found where the problem occured. It's because the SQL parameter wasn't defined properly. Instead of saying 


(
@PST decimal(5,2)
)

I only typed

(
@PST decimal
)

Anyway I thank anyone participated in the threat.
0
vljw8202
1/22/2005 11:39:51 PM
Reply:

Similar Artilces:

linking a sql field to point to the value of another sql field
is it possible to create hyperlinks in powerbuilder such that if you retrieve two fields from a database.. and want to display the first field on the screen and have it link to the value of the other field (when clicked) which is actually a URL address, you can? any help will be appreciated. thank you! ...

How to save a picture in a SQL image field and how to show a picture from a SQL image field
HI! I am searching now a real long time in the forum and I found a lot of stuff to this topic. But please help me it doesn't work! On my webapplication there is a possibility to save a private picture.If a new user is saved in the database I want to save a fixed picture as startpicture.Dim picturePath As String = Request.ServerVariables("APPL_PHYSICAL_PATH") & "img\anonymous.jpg" Please tell me the way how to save this anonymous.jpg from the picturePath into the database and after that how to display the picture. Thank you! .         ...

UserID field in SQL Express won't match to SQL 2000 field
Hi - I am using .net2, with Sql Express for the Users/Membership etc, and a SQL 2000 database for my actual web application.I want to associate my user in the aspnet_Users table of the SQL Express database, with records from the SQL 2000 database.In SQL Express the datatype for the UserID field is uniqueidentifier, length 16.  In SQL 2000 therefore, I added a table, with a column name of UserID as uniqueidentifier, length 16.When I try to insert the UserID from SQL Express into the UserID field of the SQL 2000 table, I get the error: Guid should containt 32 digits with 4 dashes (xxxxxxx...

How To -- Update Field In #Temp Table With Result From SQL Statement Inside Field
I have a stored procedure that creates a #Temp table.  In this #Temp table, I have a combination of fields with normal data (such as account number, title, etc) and I also have some fields that are "calculated" fields. The "calculated" fields are generated by making a call to our SQL Server Functions that produce and return the literal SQL needed to arrive at the calculated amounts.  So, when my stored procedure first runs, it populates the fields that have the function calls with literal SQL that, when executed, will produce the "calculated" amou...

Database triggers - SQL Server
I would like to ensure data integrity in a column (actually multiple columns will need a trigger) in my table(s) by setting up a trigger which allows an update of my database field only if the value which is being written to the field in the database exists in another column (in another "check" table).eg. I only want values "Yes", "No" or "" in many of my fields, which I store in a column named "YesNoBlank" in another table.Does anyone know the easy way to do this? / Syntax for the trigger? Why not use PK/FK instead of trigger? I ...

How do I remove dashes or ( )'s from a variable that is going to be inputed into a SQL table under a Numeric field?
I have a form where a user will input phone numbers however the SQL Table is setup as an interger so if someone puts in ( ) or -'s it will throw it off. How can I trim this string so it will be viewed as an integer in SQL?  I am thinking maybe the remove command but I am not sure. THank you!   shawn.bordeaux@justrightautosales.com Hi, You can do in the following way: strYourString.Replace("(",""); strYourString.Replace("-","");  Please do not forget to click Mark As Answer on the post that helped you. Regards,Iam...

Create access table using sql table field
 hi friends , i need create mdb file with table and data , the data will come from sql server 2005 table , for example i have table employee table contain some fields like name mobile number and others ,, now i  need to create access mdb file with table and data , data is mobile numbers of employee(just only one field) ,  i m using ASP.net C# 2.0, plz help me yarTHANKS FOR ADVANCE     Hello Raghavendra,                          &nbs...

How to call or retrieve fields from sql and display in table without using ADO.net, I'm using a dynamic link library....Is the coding different?
Help me! I'm doing my school project on Software Change Management Tool, CR Tracker. I want to display table in the webform, and the table data is retrieve form the sql server. So how do I call the sql so as to display the data in a table? hy..What does that dll contain ?Does it already contains relevant code to connect to a database ? Have a look hereThanksDinuj Nath The easy way to do this is with the use of a data bound grid. The Grid can be customised to look and feel you like. You will need to add a data adapter to your page and a grid. When you setup the data adapter you will nee...

How to define Comment fields with SQL
Using SQL Central I can define a comment as part of a column property. How do I do it using either SQL or ODBC? TIA E-mail from: Steve Garland,Hyper Logic Resource Group http://netnow.micron.net/~sgarland CAD Text Magician-CTM32 (Condoc Management), Paradox Infirmary & Resort (fix paradox files and more!) Delphi Visual CADD (tm)Component (HVCADD)- View and Manipulate AutoCAD (c) DWG Files See the COMMENT statement for adding comments programmatically. -- Jim Egan [TeamPS] Dealer Solutions, LLC Houston, TX ...

Displaying fields from a SQL table
I am really new at both ASP.NET and VB so please be kind. I also am not sure I am posting to the appropriate forum. I need to input a value on a web page and then find out if the record exists in the SQL database table or not. If the record exists, I need to format a display page with information from the record. If the record does not exist, I need to display a form that can be filled in to insert a new record in the table. I know this is probably simple, but all I can find information on is using datagrids and datagrids will not work (boss does not like). I need to create a form ...

Retrieving the description field or SQL Comment field from a view
Hi, I have managed to use the INFORMATION_SCHEMA.TABLES to retrieve a list of all my views. I was wondering if it was possible to retrieve the Description or SQL Comment field from a view via ADO.NET, which can be found in the Enterprise Manager Design View properties (right click - properties) I want to hopefully utilize this field for dynamic page titling of a datagrid bound view.  Many Thanks in anticipation!...

Inserted records missing in sql table yet tables' primary key field has been incremented.
I have a sql sever 2005 express table with an automatically incremented primary key field. I use a Detailsview to insert new records and on the Detailsview itemInserted event, i send out automated notification emails. I then received two automated emails(indicating two records have been inserted) but looking at the database, the records are not there. Whats confusing me is that even the tables primary key field had been incremented by two, an indication that indeed the two records should actually be in table.  Recovering these records is not abig deal because i can re-enter them but ia...

I imported a SQL Table into SQL DataBase, But I can not update this table even with SQL Server management Studio
I imported a SQL Table into SQL DataBase, But I can not update this table even with SQL Server management Studio When I change any data on mentioned table above, Red exclamation sign appears left of the record . How can I correct this problem?  Thanks. Try running the UPDATE via Query Analyzer...and see if you get an error.***********************Dinakar NethiLife is short. Enjoy it.***********************...

SQL table, key, field design
i am putting together an application for a client of mine that involves image heavy data handling. i have a couple of possible methods in mind of how to go about this, and would like some outside opinions, especially from any of you who may have done anything similar before. to quickly sum up the application's desired results: a photo gallery that contains four sections of job before/after photos. 1)residential 2)comercial 3) automotive and 4)specialty.  when a site browser clicks a section, it will bring up a gridview of the "key" or ideal photo (one each)from ...

Web resources about - How to define field attribute for a numeric field in SQL table? - asp.net.sql-datasource

Attribute - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Template:Attributes of God - Wikipedia, the free encyclopedia
Language: English Română Home Random Template:Attributes of God Part of a series on the Attributes of God Aseity Eternity Graciousness Holiness ...

Six Attributes Of The Perfect Facebook Page Administrator
So, here’s the thing: In many ways, hiring a Facebook page administrator is akin to hiring a poster child for your brand. This trusted manager ...

PANDA: Pose Aligned Networks for Deep Attribute Modeling - Facebook
We propose a method for inferring human attributes (such as gender, hair style, clothes style, expression, action) from images of people under ...

Facebook announces data partnerships to help advertisers target users by offline purchases and attributes ...
... will anonymously match data from consumer loyalty programs with user profiles in order to target ads by offline purchase habits and other attributes. ...

New Study Attributes Rapid Ageing Mainly To Environment Factors
New study explains why some people age faster than others.

Should I use the nofollow attribute on internal links? - YouTube
Regarding "nofollow" on internal links: Does it hurt? Does it help? I read different comments from Matt on this matter over time. What's the ...

Justin Trudeau attributes abortion stance to father's example
Liberal Leader Justin Trudeau says he is following an example set by his famous father when it comes to his position on election candidates and ...

Obama attributes western U.S. wildfires to climate change
... that has burned nearly 400 square miles in the north-central part of Washington state, along with blazes in other Western areas, can be attributed ...

Fifty Shades Of Grey Baby Births: Windsor Hospital Sees Spike In Births, Attribute Book
A significant spike in baby births at a hospital in Windsor, Ontario, has been attributed to the book Fifty Shades of Grey, which has become ...

Resources last updated: 1/23/2016 5:05:42 AM