469,332 Members | 7,053 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

change a field name in DataGrid

HS1
Hello

I have a datagrid to show data for a database table using "seclect * from
tablename"

The datagrid works OK. However, I want to change the name of the fields in
the database to other name in DataGrid. For example, a field name in
database is "FName" will be shown in dataGrid as "First Name". Could you
please tell me how to do that

Thank you for your help
Best regards
S.Hoa
Nov 21 '05 #1
5 4057
Hi
If you use, instead of "SELECT * FROM tblTableA" which returns all fields
using their Field names;
"SELECT fldA AS Orders, fldB AS Suppliers FROM tblTableA Order By fldA"
the data table will use "Orders" as an Alias to the field name fldA and
"Suppliers" as an Alias to the field name fldA. It will also order the data
table by the records in the Field fldA.

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096842002.650824@ftpsrv1...
Hello

I have a datagrid to show data for a database table using "seclect * from
tablename"

The datagrid works OK. However, I want to change the name of the fields in
the database to other name in DataGrid. For example, a field name in
database is "FName" will be shown in dataGrid as "First Name". Could you
please tell me how to do that

Thank you for your help
Best regards
S.Hoa

Nov 21 '05 #2
HS1
Hello
I already used Alias, However, if I do that the DataGrid will not display
any data (it shows "null"). I do not know how to set DataGrid to show the
Alias (in design form)
"Doug Bell" <dug@bigpond> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
Hi
If you use, instead of "SELECT * FROM tblTableA" which returns all fields
using their Field names;
"SELECT fldA AS Orders, fldB AS Suppliers FROM tblTableA Order By fldA"
the data table will use "Orders" as an Alias to the field name fldA and
"Suppliers" as an Alias to the field name fldA. It will also order the data table by the records in the Field fldA.

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096842002.650824@ftpsrv1...
Hello

I have a datagrid to show data for a database table using "seclect * from tablename"

The datagrid works OK. However, I want to change the name of the fields in the database to other name in DataGrid. For example, a field name in
database is "FName" will be shown in dataGrid as "First Name". Could you
please tell me how to do that

Thank you for your help
Best regards
S.Hoa


Nov 21 '05 #3
Hi,
I am a bit confused.
If you are using Select * then you are not using alias for field names.
With your example it would be:
"SELECT FName AS [First Name] FROM tablename"

the brackets are needed if you use spaces, keywords or special characters.

Doug

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096843814.417496@ftpsrv1...
Hello
I already used Alias, However, if I do that the DataGrid will not display
any data (it shows "null"). I do not know how to set DataGrid to show the
Alias (in design form)
"Doug Bell" <dug@bigpond> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
Hi
If you use, instead of "SELECT * FROM tblTableA" which returns all fields
using their Field names;
"SELECT fldA AS Orders, fldB AS Suppliers FROM tblTableA Order By fldA"
the data table will use "Orders" as an Alias to the field name fldA and
"Suppliers" as an Alias to the field name fldA. It will also order the data
table by the records in the Field fldA.

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096842002.650824@ftpsrv1...
Hello

I have a datagrid to show data for a database table using "seclect *

from tablename"

The datagrid works OK. However, I want to change the name of the fields in
the database to other name in DataGrid. For example, a field name in
database is "FName" will be shown in dataGrid as "First Name". Could

you please tell me how to do that

Thank you for your help
Best regards
S.Hoa



Nov 21 '05 #4
HS1
Thanks
I forget to tell you that I tried to use "Select FName As [FirtName]". When
I did that, in the DataGrid, the column is still "FName" and the value is
"null"
I think that I set wrong DataGrid

"Doug Bell" <dug@bigpond> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
Hi,
I am a bit confused.
If you are using Select * then you are not using alias for field names.
With your example it would be:
"SELECT FName AS [First Name] FROM tablename"

the brackets are needed if you use spaces, keywords or special characters.

Doug

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096843814.417496@ftpsrv1...
Hello
I already used Alias, However, if I do that the DataGrid will not display
any data (it shows "null"). I do not know how to set DataGrid to show the Alias (in design form)
"Doug Bell" <dug@bigpond> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
Hi
If you use, instead of "SELECT * FROM tblTableA" which returns all

fields using their Field names;
"SELECT fldA AS Orders, fldB AS Suppliers FROM tblTableA Order By fldA" the data table will use "Orders" as an Alias to the field name fldA and "Suppliers" as an Alias to the field name fldA. It will also order the

data
table by the records in the Field fldA.

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096842002.650824@ftpsrv1...
> Hello
>
> I have a datagrid to show data for a database table using "seclect *

from
> tablename"
>
> The datagrid works OK. However, I want to change the name of the fields
in
> the database to other name in DataGrid. For example, a field name in
> database is "FName" will be shown in dataGrid as "First Name". Could

you > please tell me how to do that
>
> Thank you for your help
> Best regards
> S.Hoa
>
>



Nov 21 '05 #5
use a DataGridTableStyle, then apply a DataGridColumnStyle to it. You can
change this by manipulating the DataColumn's name, but I'd recommend against
doing that in most cases b/c you'll need to remember to use that Alias
everywhere and chances are you'll forget at some point (or some other
developer will) .
http://www.knowdotnet.com/articles/cgrid.html
Also, unless you have a really small table and/or actually need every
column, stay away from SELECT * because you'll pull over a lot of data that
you don't need which is cached locally - this can be a real performance
killer. (Doug already mentioned using the aliases instead of SELECT *, I'm
just seconding that opinion)

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"HS1" <so*@slingshot.co.nz> wrote in message
news:1096852553.230267@ftpsrv1...
Thanks
I forget to tell you that I tried to use "Select FName As [FirtName]". When I did that, in the DataGrid, the column is still "FName" and the value is
"null"
I think that I set wrong DataGrid

"Doug Bell" <dug@bigpond> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
Hi,
I am a bit confused.
If you are using Select * then you are not using alias for field names.
With your example it would be:
"SELECT FName AS [First Name] FROM tablename"

the brackets are needed if you use spaces, keywords or special characters.

Doug

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096843814.417496@ftpsrv1...
Hello
I already used Alias, However, if I do that the DataGrid will not display any data (it shows "null"). I do not know how to set DataGrid to show the Alias (in design form)
"Doug Bell" <dug@bigpond> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
> Hi
> If you use, instead of "SELECT * FROM tblTableA" which returns all

fields
> using their Field names;
> "SELECT fldA AS Orders, fldB AS Suppliers FROM tblTableA Order By fldA" > the data table will use "Orders" as an Alias to the field name fldA and > "Suppliers" as an Alias to the field name fldA. It will also order the data
> table by the records in the Field fldA.
>
> "HS1" <so*@slingshot.co.nz> wrote in message
> news:1096842002.650824@ftpsrv1...
> > Hello
> >
> > I have a datagrid to show data for a database table using "seclect * from
> > tablename"
> >
> > The datagrid works OK. However, I want to change the name of the

fields
in
> > the database to other name in DataGrid. For example, a field name in > > database is "FName" will be shown in dataGrid as "First Name".

Could you
> > please tell me how to do that
> >
> > Thank you for your help
> > Best regards
> > S.Hoa
> >
> >
>
>



Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Harry Devine | last post: by
6 posts views Thread by Red | last post: by
1 post views Thread by Julius Fenata | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.