473,699 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4238
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******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP15.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******** ******@TK2MSFTN GP12.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 DataGridTableSt yle, then apply a DataGridColumnS tyle 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******** ******@TK2MSFTN GP15.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******** ******@TK2MSFTN GP12.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3330
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on different rows in the datagrid, the textbox content doesn't change to reflect the change. How can I address this? Also, If the user change the text in the textbox then how do I refesh the display in the datagrid to reflect the changes? ...
0
2653
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the CompanyName, ContactName, and ContactTitle columns from the Customers table in the Northwind database. Whenever the value of ContactTitle equals "Owner" we will change the font color to red. We can do this by using an ItemTemplate where we have...
2
2694
by: J Sahoo | last post by:
Hi, I have a browse page where I am showing few fields from my SQL Server table. One of the field is Image type, all the fields are bound to a single table. I want to show the image from the table on this browse along with the other fields. Here is the code what I have from the HTML view, I am using a datagrid to show the result. It does not show the image rather it shows "System.Byte " on the output. I did not have any code behind...
1
3778
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to update that last 4 fields. The last field is a Yes/No value in Access. Using the OleDbCommand, if I do not consider the Yes/No field, the ExecuteNonQuery command, using my UPDATE SQL statement, updates the record correctly. However, if I put the Yes/No field into the mix, ExecuteNonQuery...
6
1843
by: Red | last post by:
Hi all, I would like to ask how to combine 2 field into one column. For example I have field first name and last name. When I show it to the datagrid I want to show it as one column, for example first name: Jack, lastname: sun become Jack sun. Thanks
1
2833
by: Julius Fenata | last post by:
Dear all, I need help to change my item-template value format... Here is my case, I have a datagrid, with 'SubjectPrice' field, and when the grid displayed, my 'SubjectPrice' field displayed as this format: $30,000.00, because I put it this format {0:C}. I need to re-format as only this value (example: 30.000 - without currency, without decimal & using dot for thousand separator). But how to re-format my
6
6230
by: HS1 | last post by:
Hello I have a table in Access Database. This table has a AutoNumber field. I use a DataGrid to show that table When I insert a new record in for this table using a DataGrid, there is a message that asks me to enter the value for this AutoNumber field. Why I have to do that? Could you please help
3
1877
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is not there, of course. How do I get that field back into the datatable for the database update? TIA, Larry Woods
2
3833
by: remya1000 | last post by:
i'm using VB.NET. and its a windows application. in my program i need to display a table in datagrid. so i created the table using DataTable and i'm calling that dataTable to dataGrid. and its working fine... but according to one of the field in that table i need to change the back color of that row. one of the field in that table called "Active", it will have value as True or False. so if Active =True then i need that corresponding row...
0
9199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8947
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8902
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5891
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4392
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.