"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:Oc**************@TK2MSFTNGP03.phx.gbl...
>I built a webpage using vb.net (.net 2.0) that creates a form letter. This
letter pulls data from a database. Although I populate the address with the
person's full name, which comes from the name column of a customer table, I
need to just get the first name for the Dear part of the letter (ie: Dear
John instead of Dear John Smith). It would be easy if the name was in two
parts in the table (First name and Last name column) but, that isn't the
case.
I've been using a datalist to pull data out of the database and populate
it to the webpage. How could I just get the first name instead of the
whole name?
TIA,
Jim
Jim,
Your first decision is where to do the extraction of the name. It will
be done either on the database server or by the application. If you are
using SQL Server you can create a computed colum which can be used to return
the name. If you are going to do it in the application then you will
extract the name from the returned database row.
Big problem is this: From this list of names what is the first name:
Jean Francois De Poulet
John Smith
Jean De Poulet
As you can see there is an exception for each rule. In over 30 years of
working databases I see this problem all the time. The simplest although
somewhat error prone is to split the name using space as the delimiter.
Then use the first member of the split. At least in the above list 2 of the
3 would be correct.
Living in Canada as you see makes this almost impossible.
You would do this either as a function if you are using the <%#
Eval("Name") %type binding you can create a function to return the value
and using this in the Eval expression or you can do the processing in the
ItemDataBound event of the datalist.
Hope this helps
Lloyd Sheen