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

change a field name in DataGrid

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.