By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

Defining data types for fields, when you a create a file

P: n/a
Hi All,

When I create fields (in files) I need assign a data type like char,
varchar, money etc.

I have some questions about the data types when you create fields in a
file.

What is the difference between data type 'CHAR' and 'TEXT'?
When do you use 'VAR' in your datatype word? e.g. VARCHAR ?
What is the difference 'NVARCHAR' & 'VARCHAR' & 'CHAR'?
What is the 'N' in 'VARCHAR'?

Let's say I would like to create a file see below for the fields.
What data type do you assign for it? Can someone help me assigning data
types?

File1
======
Name data type?
Address data type?
City data type?
Salary Amount (2 decimal) data type?
Age data type?
Gender (value M/F) data type?
length (2 decimal) data type?
Quantity ( 0 decimal) data type?
Cost price (4 decimal) data type?
Extented price ( 2 decimal) data type?
Birth Date data type?
User id data type?
Time entered data type?
Thank you clarifying these datatypes.

Regards,

Mesut

Mar 9 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"mesut demir" <me*********@noveonbe.com> schrieb im Newsbeitrag
news:11*********************@i39g2000cwa.googlegro ups.com...
Hi All,

When I create fields (in files) I need assign a data type like char,
varchar, money etc.

I have some questions about the data types when you create fields in a
file.

What is the difference between data type 'CHAR' and 'TEXT'?
When do you use 'VAR' in your datatype word? e.g. VARCHAR ?
What is the difference 'NVARCHAR' & 'VARCHAR' & 'CHAR'?
What is the 'N' in 'VARCHAR'?
These are names of data types used in databases. In VB.Net we have other
data types, like String, Integer etc. Why do you refer to the database data
types if you want to store something in a file? That can be right - just
asking.

To get an explanation of the data types, look at the documentation of the
database. For SQL Server:
http://msdn.microsoft.com/library/en...da-db_7msw.asp

Mapped data types:
http://msdn.microsoft.com/library/en...kdatatypes.asp

Let's say I would like to create a file see below for the fields.
What data type do you assign for it? Can someone help me assigning data
types?

File1
======
Name data type?
Address data type?
City data type?
Salary Amount (2 decimal) data type?
Age data type?
Gender (value M/F) data type?
length (2 decimal) data type?
Quantity ( 0 decimal) data type?
Cost price (4 decimal) data type?
Extented price ( 2 decimal) data type?
Birth Date data type?
User id data type?
Time entered data type?
Thank you clarifying these datatypes.

http://msdn.microsoft.com/library/en...nDataTypes.asp

http://msdn.microsoft.com/library/en...asslibrary.asp

(Below head line "System Namespace", some basic data types are listed)
Armin

Mar 9 '06 #2

P: n/a
Hi Armin,

Thank you for repsonse. I learnt more from your links you sent. But I
would like to create a file and I create some fields. I need to assign
data types to that fields. My problem is which data type do I assign to
the fields.
e.g. I create a file and the file has a field "NAME" 50 positions.
Okay what should be the DATA type for this in is it CHAR or VARCHAR or
NVARCHAR or NVAR or TEXT or NTEXT ?????....

For that reason I have created a file BELOW but what should be the data
type of these fields below
Can you help me with that ? From there I can learn...

TESTFILE:
--------------
Name data type?
Address data type?
City data type?
Salary Amount (2 decimal) data type?
Age data type?
Gender (value M/F) data type?
length (2 decimal) data type?
Quantity ( 0 decimal) data type?
Cost price (4 decimal) data type?
Extented price ( 2 decimal) data type?
Birth Date data type?
User id data type?
Time entered data type?

Thanks again for your response.

regards,

Mesut

Mar 9 '06 #3

P: n/a
"mesut demir" <me*********@noveonbe.com> schrieb
Hi Armin,

Thank you for repsonse. I learnt more from your links you sent. But
I would like to create a file and I create some fields. I need to
assign data types to that fields. My problem is which data type do I
assign to the fields.
e.g. I create a file and the file has a field "NAME" 50 positions.
Okay what should be the DATA type for this in is it CHAR or VARCHAR
or NVARCHAR or NVAR or TEXT or NTEXT ?????....
No, it's neither char nor varchar nor nvarchar because the file is not a
database.

Actually there are two questions:

a) Which data type to use for variables to hold the values?

See the links given to choose the right type. (String for Name, Decimal for
Salary etc.)

b) How to store the values in the file?

This depends on a). You can store each type in different formats in a file.
For example, you can store a Decimal value in a binary format or you can
convert it to a String before.
If you store Strings in a file, you must choose the right encoding. In
memory, Strings are stored as Unicode character codes. If you write a String
to a file, you can use different encodings like Unicode, UTF-8, ANSI etc. Be
aware that some encodings do not have a fixed byte count per char, like
UTF-8. Have a look at the System.Text.Encoding class for more information.
Moreover, do you have a free choice of the file format or can you specify it
on your own? Why did you choose this format? Do you want to have a random
access file (fixed record length)
http://msdn.microsoft.com/library/en...FileAccess.asp

or a sequential file (different record length)?

http://msdn.microsoft.com/library/en...FileAccess.asp

There are also XML files, and we have serialization.

http://msdn.microsoft.com/library/en...ingobjects.asp

Currently, my impression is that a random access file (see 1st link above)
is appropriate.

But, the main question is: What is your intention?

For that reason I have created a file BELOW but what should be the
data type of these fields below
Can you help me with that ? From there I can learn...

TESTFILE:
--------------
Name data type?
Address data type?
City data type?
Salary Amount (2 decimal) data type?
Age data type?
Gender (value M/F) data type?
length (2 decimal) data type?
Quantity ( 0 decimal) data type?
Cost price (4 decimal) data type?
Extented price ( 2 decimal) data type?
Birth Date data type?
User id data type?
Time entered data type?

Armin

Mar 9 '06 #4

P: n/a
Hi Armin,

Sorry that I express my self wrong.... I'm coming from 3GL world so
with FILE I meant database file...

So I would like to create a database file or database table (to store
the name, adress etc the record information )...
I'm struggling about assigning correct datatypes to fields.

So this is not a programming question... I use the Microsoft SQL
database.

intention: I would like to create some DATABASE files and I would like
to access via VB.NET. I have installed on my pc Visual Basic Express
Edition, + Free MS SQL -> the free ware package to learn Visual basic
..Net.
I would liket to create some DATABASE TABLES/FILES and try to fill in
in my program in form. I need to define the DATABASE tables (fields)

I hope I explained well this time...

Sorry again I expressed myself wrong in my previous e-mail and I hope
this time I wrote correct, ...

Thanks again for your repsonse,

best regards,

Mesut

Mar 9 '06 #5

P: n/a
Armin's first link is your holy grail. It details exactly what each
datatype is.

In general...

We use nvarchar to store almost all Strings. The n indicates it is a
unicode field. You will also need to specify length (up to 4000
characters).

Other notable types are int, float, money, datetime, etc. Money will
actually give you 4 decimals but it's handy.

Again, check that link above for the nitty gritty details of each type.

e.g.
Name nvarchar(50)
Address nvarchar(50)
City nvarchar(20)
Salary Amount (2 decimal) money

Mar 9 '06 #6

P: n/a
"mesut demir" <me*********@noveonbe.com> schrieb
Hi Armin,

Sorry that I express my self wrong.... I'm coming from 3GL world so
with FILE I meant database file...

So I would like to create a database file or database table (to
store the name, adress etc the record information )...
I'm struggling about assigning correct datatypes to fields.

So this is not a programming question... I use the Microsoft SQL
database.

intention: I would like to create some DATABASE files and I would
like to access via VB.NET. I have installed on my pc Visual Basic
Express Edition, + Free MS SQL -> the free ware package to learn
Visual basic .Net.
I would liket to create some DATABASE TABLES/FILES and try to fill
in in my program in form. I need to define the DATABASE tables
(fields)

I hope I explained well this time...

Now I understand. :-) Well, I gave you to the link to the list of available
data types for SQL server. Accessing databases is a broad topic, so I can
only post the link to the documentation:

http://msdn.microsoft.com/library/en...withadonet.asp

Maybe you also want to download the "SQL Server Management Studio Express"
(3rd link):

http://msdn.microsoft.com/sql/express/

There is also a link to the "SQL Server 2005 Books Online (December 2005)".

The best newsgroup for ADO.Net related questions is
microsoft.public.dotnet.framework.adonet.

Armin

Mar 9 '06 #7

P: n/a
Hi Figital,

Thank you too... I have looked at the links and printed Armin send. At
the links is an overview which data types exist. I see there are some
data types for NUMERIC, Alpha-NUMERIC, DECIMALS etc.

e.g. Why do you use NVARCAR for NAME/ADDRESS/ etc. in your sample? Why
don't you use NCHAR or NTEXT or maybe CHAR? and Why do you use Data
type MONEY for Salary or AMOUNTS and not DECIMAL?

Last stupid question... Will there be big difference using VARIABLE
data types rather than FIXED datatypes. e.g. between NCHAR & NVARCHAR

Thanks again for your answers,

regards,

Mesut

Mar 9 '06 #8

P: n/a
I have never used SqlVariant. From what I understand you shouldn't use
this unless you have a good reason.

nvarchar is (usually) better than nchar because it only takes up as
much space as need PER record.

nvarchar (50) is a max length of 50, whereas nchar(50) is exactly 50.
Thus, the space required to store "Michael" would be approx 6 vs 50.

Char _can_ have benefits but for this type of data, you won't see them.

I have never used nText because I have never needed moer than 4000
characters in a single field. If you were storing things bigger than
that, you would need it. In general, I use the smallest datatype that
gets the job done.

Bigger datatypes don't just make for bigger databases...they can effect
performance all around.

While I've never actually done this myself, you might find it
informative to poke around the Northwind database to see how things are
setup.

Mar 9 '06 #9

P: n/a
Thank you very much again Figital. I now much have better understing
data types.

btw Armin thank you too for the usefull links you sent...

best regards,

Mesut

Mar 9 '06 #10

P: n/a
Mesut,

Be aware that a field type name on database server mark A can mean or be
stored something different as on server mark B.

Cor

"mesut demir" <me***@edpnet.be> schreef in bericht
news:11*********************@j52g2000cwj.googlegro ups.com...
Thank you very much again Figital. I now much have better understing
data types.

btw Armin thank you too for the usefull links you sent...

best regards,

Mesut

Mar 10 '06 #11

P: n/a
Hi Cor,

I learnt 1 more thing now. Thank you for tip, I'll keep in mind....

best regards,

Mesut

Mar 10 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.