I have a DataTable that I need to merge the 'lastname' and 'firstname'
fields to be displayed in a datagrid. I know I can use the SQL statement to
merge the fields into one, but I want to know if it's possible to do through
the DataTable, DataView or DataGrid that I have already created to display
the data.
This should be easy...right?
-bruce duncan 11 19519
Hi,
Add a new calculated column to your dataset. Use that column as the
displaymember in the listbox.
Dim dc As DataColumn
'
' Add a new column in clients table which
' is full name.
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "LastName + ', ' + FirstName"
dsClient.Tables(0).Columns.Add(dc)
Ken
--------------------
"Bruce D" <br*************@hotmail.com> wrote in message
news:11*************@corp.supernews.com...
I have a DataTable that I need to merge the 'lastname' and 'firstname'
fields to be displayed in a datagrid. I know I can use the SQL statement to
merge the fields into one, but I want to know if it's possible to do through
the DataTable, DataView or DataGrid that I have already created to display
the data.
This should be easy...right?
-bruce duncan
Bruce,
You can by adding an extra column to your datastable and use an expression
in the constructor of that. http://msdn.microsoft.com/library/de...ctortopic4.asp
And do than a datatable.acceptchanges to set the rowstates back to unchanged
(This is all direct after that you filled your datatable)
However you can only use this to display and should make probably directly
from it a readonly field in your styles (I never did it this way with a
datagrid, so that should you try). http://msdn.microsoft.com/library/de...donlytopic.asp
I hope this helps?
Cor
Bruce,
Have you tried adding a computed column to your DataTable?
Assuming you have a "firstname" and "lastname" column in your DataTable, you
can define a "fullname" computed column with:
Dim table As DataTable
table.Columns.Add("fullname", GetType(String), "lastname + ', ' +
firstname")
For details on what is allowed in the expression, see the
DataColumn.Expression help topic.
Hope this helps
Jay
"Bruce D" <br*************@hotmail.com> wrote in message
news:11*************@corp.supernews.com... I have a DataTable that I need to merge the 'lastname' and 'firstname' fields to be displayed in a datagrid. I know I can use the SQL statement to merge the fields into one, but I want to know if it's possible to do through the DataTable, DataView or DataGrid that I have already created to display the data. This should be easy...right?
-bruce duncan
Ken, dc.DataType = System.Type.GetType("System.String")
Rather then risk a runtime error with a bad string name on Type.GetType, I
normally use the GetType function:
dc.DataType = GetType(System.String)
This way if there was a typo in the type name, then I receive a compile
error, rather then a runtime error.
Otherwise the results are the same...
Just a thought
Jay
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eA**************@TK2MSFTNGP12.phx.gbl... Hi,
Add a new calculated column to your dataset. Use that column as the displaymember in the listbox.
Dim dc As DataColumn
'
' Add a new column in clients table which
' is full name.
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "LastName + ', ' + FirstName"
dsClient.Tables(0).Columns.Add(dc) Ken
-------------------- "Bruce D" <br*************@hotmail.com> wrote in message news:11*************@corp.supernews.com... I have a DataTable that I need to merge the 'lastname' and 'firstname' fields to be displayed in a datagrid. I know I can use the SQL statement to merge the fields into one, but I want to know if it's possible to do through the DataTable, DataView or DataGrid that I have already created to display the data. This should be easy...right?
-bruce duncan
I should add that the GetType() function/keyword also supports intellisense,
so you can "pick" the desired type.
I will however use Type.GetType when I am reading the type name from the
app.config or other config file...
Just a thought
Jay
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:em*************@TK2MSFTNGP12.phx.gbl... Ken, dc.DataType = System.Type.GetType("System.String") Rather then risk a runtime error with a bad string name on Type.GetType, I normally use the GetType function:
dc.DataType = GetType(System.String)
This way if there was a typo in the type name, then I receive a compile error, rather then a runtime error.
Otherwise the results are the same...
Just a thought Jay
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:eA**************@TK2MSFTNGP12.phx.gbl... Hi,
Add a new calculated column to your dataset. Use that column as the displaymember in the listbox.
Dim dc As DataColumn
'
' Add a new column in clients table which
' is full name.
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "LastName + ', ' + FirstName"
dsClient.Tables(0).Columns.Add(dc) Ken
-------------------- "Bruce D" <br*************@hotmail.com> wrote in message news:11*************@corp.supernews.com... I have a DataTable that I need to merge the 'lastname' and 'firstname' fields to be displayed in a datagrid. I know I can use the SQL statement to merge the fields into one, but I want to know if it's possible to do through the DataTable, DataView or DataGrid that I have already created to display the data. This should be easy...right?
-bruce duncan
Jay,
Just too your attentition, I have seen that this gave once by somebody
misunderstandings. Have you tried adding a computed column to your DataTable?
It was mixed up with DataTable.Compute. As you know are it not only English
speaking people who visit this newsgroup.
Just to inform.
Cor
Hi,
You are right Type.GetType would be a better choice. Suprised you
get a compile time error. Copied this code from a working project.
Ken
----------------
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I should add that the GetType() function/keyword also supports intellisense,
so you can "pick" the desired type.
I will however use Type.GetType when I am reading the type name from the
app.config or other config file...
Just a thought
Jay
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:em*************@TK2MSFTNGP12.phx.gbl... Ken, dc.DataType = System.Type.GetType("System.String") Rather then risk a runtime error with a bad string name on Type.GetType, I normally use the GetType function:
dc.DataType = GetType(System.String)
This way if there was a typo in the type name, then I receive a compile error, rather then a runtime error.
Otherwise the results are the same...
Just a thought Jay
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:eA**************@TK2MSFTNGP12.phx.gbl... Hi,
Add a new calculated column to your dataset. Use that column as the displaymember in the listbox.
Dim dc As DataColumn
'
' Add a new column in clients table which
' is full name.
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "LastName + ', ' + FirstName"
dsClient.Tables(0).Columns.Add(dc) Ken
-------------------- "Bruce D" <br*************@hotmail.com> wrote in message news:11*************@corp.supernews.com... I have a DataTable that I need to merge the 'lastname' and 'firstname' fields to be displayed in a datagrid. I know I can use the SQL statement to merge the fields into one, but I want to know if it's possible to do through the DataTable, DataView or DataGrid that I have already created to display the data. This should be easy...right?
-bruce duncan
Cor,
Huh?
"Computed column" & "calculated column" are terms MSDN uses: http://msdn.microsoft.com/library/de...ctorTopic4.asp http://msdn.microsoft.com/library/de...ctortopic5.asp http://msdn.microsoft.com/library/de...ssionTopic.asp
Don't you agree that it is better to use the nomenclature that MS uses in
its books & on MSDN, rather then making up my own words?
Also, the example code itself rather clear that I was refering to a new
column (table.Columns.Add) rather then calling a method (DataTable.Compute)!
Hope this helps
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uA**************@TK2MSFTNGP09.phx.gbl... Jay,
Just too your attentition, I have seen that this gave once by somebody misunderstandings.
Have you tried adding a computed column to your DataTable? It was mixed up with DataTable.Compute. As you know are it not only English speaking people who visit this newsgroup.
Just to inform.
Cor
Ken, You are right Type.GetType would be a better choice.
Err...
Actually I was suggesting that a GetType expression http://msdn.microsoft.com/library/de...c911_25_41.asp
would be a better choice over Type.GetType.
Your code does not have a compile time error! I was stating if you
miss-typed the type name on a GetType expression you will receive a compile
error, however if you miss type the type name on the parameter to
Type.GetType you will receive a runtime error instead of a compile time
error... As the GetType expression expects an Identifier, where as
Type.GetType expects a String.
Hope this helps
Jay
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:u6**************@TK2MSFTNGP12.phx.gbl... Hi,
You are right Type.GetType would be a better choice. Suprised you get a compile time error. Copied this code from a working project.
Ken ---------------- "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... I should add that the GetType() function/keyword also supports intellisense, so you can "pick" the desired type.
I will however use Type.GetType when I am reading the type name from the app.config or other config file...
Just a thought Jay
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:em*************@TK2MSFTNGP12.phx.gbl... Ken, dc.DataType = System.Type.GetType("System.String") Rather then risk a runtime error with a bad string name on Type.GetType, I normally use the GetType function:
dc.DataType = GetType(System.String)
This way if there was a typo in the type name, then I receive a compile error, rather then a runtime error.
Otherwise the results are the same...
Just a thought Jay
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:eA**************@TK2MSFTNGP12.phx.gbl... Hi,
Add a new calculated column to your dataset. Use that column as the displaymember in the listbox.
Dim dc As DataColumn
'
' Add a new column in clients table which
' is full name.
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "LastName + ', ' + FirstName"
dsClient.Tables(0).Columns.Add(dc) Ken
-------------------- "Bruce D" <br*************@hotmail.com> wrote in message news:11*************@corp.supernews.com... I have a DataTable that I need to merge the 'lastname' and 'firstname' fields to be displayed in a datagrid. I know I can use the SQL statement to merge the fields into one, but I want to know if it's possible to do through the DataTable, DataView or DataGrid that I have already created to display the data. This should be easy...right?
-bruce duncan
Jay,
As I wrote often before, this is not meant as any kind of negative critique.
I would not know why I should do that.
There was nothing wrong with your text except, that that "compute" catched
my eyes.
The word "compute" by the way on your showed pages is only used 1 time as a
minor text for the same sample on 2 pages, not in the description. The used
word "calculate" gives for me a better distinct from the vertical "compute".
Where I don't discuss the meaning in English from those words.
You are free to do yourself with what I wrote of course, it was just to help
to make it even better.
Cor
You know Cor this post & your previous post on Computer Columns really don't
warrant a response from me.
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl... Jay,
As I wrote often before, this is not meant as any kind of negative critique. I would not know why I should do that.
There was nothing wrong with your text except, that that "compute" catched my eyes.
The word "compute" by the way on your showed pages is only used 1 time as a minor text for the same sample on 2 pages, not in the description. The used word "calculate" gives for me a better distinct from the vertical "compute". Where I don't discuss the meaning in English from those words.
You are free to do yourself with what I wrote of course, it was just to help to make it even better.
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: beerman |
last post by:
I have developed an app (in Access 2002) that dynamically creates a
table, and the fields in that table, for propagation based on the max
number of...
|
by: Joey Lee |
last post by:
Hi,
I am confused as what the DataSet Merge() function does.
Currently I have two datatable which was selected from different table in
mssql....
|
by: Chris Ashley |
last post by:
Hi there,
If i have a dataset which has a datatable which has fields matching an
existing SQL Server DB Table exactly, is there an easy way to...
|
by: muntyanu |
last post by:
Hi all,
I have problem when merging existing DataTable into new dataset.
DataSet ds = new DataSet();
while ( done )
{
// fill...
|
by: Allen |
last post by:
We converted our app from 1.1 to 2 and some code was no longer working.
The case: From a non typed datatable, convert it to a typed one.
How to...
|
by: John Cosmas |
last post by:
I have a DATATABLE which I have populated in my application, and I need it
written out to a particular table I specify in my ACCESS database. My...
|
by: Matt F |
last post by:
I'm having difficulty with a function and can't find what the problem is.
The code is below. Essentially, it works fine if the target table (tbl...
|
by: mj2736 |
last post by:
I'm a little confused about DataTable.Merge(). I have two DataTable
objects with the same structure - dtOrig and dtCurrent. The end result
I'm...
|
by: joproulx |
last post by:
Hello all,
Here is my problem:
I am trying to merge 2 datasets but I don't want to overwrite rows
that are already modified in my working dataset....
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |