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

Home Posts Topics Members FAQ

Building Dynamic Strings from Database Values

Hi All

Hope someone can help us with an issue here.

We use an ASP application in which we send out emails using cdo for various
events.

At present the email text is hard coded into the code. for example

strMessage = "Dear " & rs("firstname" )
strMessage = strMessage & "Your request has been approved with reference id
" & rs("id")

This causes an administration overhead as everytime the text of the message
needs to be changed we need to alter the code to incorporate text or
database values.

What we want is to store the message text into a table so it can be altered
by the application administrators through GUI by adding the text through
freetext entry and field names though a dropdown.

and then use something like

strFirstName = rs("firstname" )

Set rst = Server.CreateOb ject("ADODB.Rec ordset")
sql = "select * from templates where id = 1"
rst.Open sql, conn
strText = rst("templateda ta")

Response.write "templateda te " & strText

Now is the strText Contains the text Dear {FirstName} This is a contract
between the two parties.

How do I change all occurances of the {FirstName} with strFirstName such
that if firstname is "SIMON" the strText should be

"Dear SIMON This is a contract between the two parties."

Any help is appreciated.
Jul 22 '05 #1
5 1380
JP SIngh wrote:
Set rst = Server.CreateOb ject("ADODB.Rec ordset")
sql = "select * from templates where id = 1"
Don't use selstar: http://www.aspfaq.com/show.asp?id=2096
rst.Open sql, conn
strText = rst("templateda ta")

Response.write "templateda te " & strText

Now is the strText Contains the text Dear {FirstName} This is a
contract between the two parties.

How do I change all occurances of the {FirstName} with strFirstName
such that if firstname is "SIMON" the strText should be

"Dear SIMON This is a contract between the two parties."

Use the Replace function:

strText = Replace(strText ,"{FirstName }", strFirstName)

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #2
strText = Replace(rst("te mplatedata"), "FIRSTNAME" , rst("firstname" ))

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"JP SIngh" <no**@none.co m> wrote in message news:uJ******** ******@TK2MSFTN GP09.phx.gbl...
Hi All

Hope someone can help us with an issue here.

We use an ASP application in which we send out emails using cdo for various
events.

At present the email text is hard coded into the code. for example

strMessage = "Dear " & rs("firstname" )
strMessage = strMessage & "Your request has been approved with reference id
" & rs("id")

This causes an administration overhead as everytime the text of the message
needs to be changed we need to alter the code to incorporate text or
database values.

What we want is to store the message text into a table so it can be altered
by the application administrators through GUI by adding the text through
freetext entry and field names though a dropdown.

and then use something like

strFirstName = rs("firstname" )

Set rst = Server.CreateOb ject("ADODB.Rec ordset")
sql = "select * from templates where id = 1"
rst.Open sql, conn
strText = rst("templateda ta")

Response.write "templateda te " & strText

Now is the strText Contains the text Dear {FirstName} This is a contract
between the two parties.

How do I change all occurances of the {FirstName} with strFirstName such
that if firstname is "SIMON" the strText should be

"Dear SIMON This is a contract between the two parties."

Any help is appreciated.



Jul 22 '05 #3
Great. Thanks a quick reply.

Now I have potentially 20-30 field names in the same message. Do I have to
have 30 replace statements or can i write something generic

the string name in the message will always correspond to the fieldname in
the database

for example

{FirstName} - rs("FirstName" )
{LastName} - rs("LastName")
{Department} - rs("Department" )
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
JP SIngh wrote:
Set rst = Server.CreateOb ject("ADODB.Rec ordset")
sql = "select * from templates where id = 1"


Don't use selstar: http://www.aspfaq.com/show.asp?id=2096
rst.Open sql, conn
strText = rst("templateda ta")

Response.write "templateda te " & strText

Now is the strText Contains the text Dear {FirstName} This is a
contract between the two parties.

How do I change all occurances of the {FirstName} with strFirstName
such that if firstname is "SIMON" the strText should be

"Dear SIMON This is a contract between the two parties."

Use the Replace function:

strText = Replace(strText ,"{FirstName }", strFirstName)

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jul 22 '05 #4
You'll need to do a loop:

for each fld in rs.Fields
strText=Replace (strText,"{" & fld.Name & "}", fld.Value)
next

Bob Barrows

JP SIngh wrote:
Great. Thanks a quick reply.

Now I have potentially 20-30 field names in the same message. Do I
have to have 30 replace statements or can i write something generic

the string name in the message will always correspond to the
fieldname in the database

for example

{FirstName} - rs("FirstName" )
{LastName} - rs("LastName")
{Department} - rs("Department" )
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
JP SIngh wrote:
Set rst = Server.CreateOb ject("ADODB.Rec ordset")
sql = "select * from templates where id = 1"


Don't use selstar: http://www.aspfaq.com/show.asp?id=2096
rst.Open sql, conn
strText = rst("templateda ta")

Response.write "templateda te " & strText

Now is the strText Contains the text Dear {FirstName} This is a
contract between the two parties.

How do I change all occurances of the {FirstName} with strFirstName
such that if firstname is "SIMON" the strText should be

"Dear SIMON This is a contract between the two parties."

Use the Replace function:

strText = Replace(strText ,"{FirstName }", strFirstName)

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get
a quicker response by posting to the newsgroup.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #5
You could also use the standard .NET placeholder {0} for first parameter,
{1} for second etc...

Patrice

--

"JP SIngh" <no**@none.co m> a écrit dans le message de
news:u9******** ******@TK2MSFTN GP09.phx.gbl...
Great. Thanks a quick reply.

Now I have potentially 20-30 field names in the same message. Do I have to
have 30 replace statements or can i write something generic

the string name in the message will always correspond to the fieldname in
the database

for example

{FirstName} - rs("FirstName" )
{LastName} - rs("LastName")
{Department} - rs("Department" )
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
JP SIngh wrote:
Set rst = Server.CreateOb ject("ADODB.Rec ordset")
sql = "select * from templates where id = 1"


Don't use selstar: http://www.aspfaq.com/show.asp?id=2096
rst.Open sql, conn
strText = rst("templateda ta")

Response.write "templateda te " & strText

Now is the strText Contains the text Dear {FirstName} This is a
contract between the two parties.

How do I change all occurances of the {FirstName} with strFirstName
such that if firstname is "SIMON" the strText should be

"Dear SIMON This is a contract between the two parties."

Use the Replace function:

strText = Replace(strText ,"{FirstName }", strFirstName)

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3414
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password are input in login screen. The password in the database is a number field. I am writing the dynamic sql statement as follows below. I believe I am going wrong in the password section of the code. I appreciate any help. Thanks. Regards.
1
1389
by: webguynow | last post by:
My Dynamic variables print out, same as strings but aren't the same. They are not correct when using them as DB.connection vars. I was using my own routine, that read in string values from a config file, that had entries like host=localhost etc, etc. After reading, I used explode with "=" as a separator,... then finally created some dynamic vars $$key=$val They are valid, it seems and printout/echo correct normal values:...
1
17666
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
5
3756
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I believe the problem centers around my handling of strings, arrays, pointers and dynamic memory allocation. Here is the problem I'm trying to solve: I want to fill a list box with a list of Project Names from a database (in Palm this is more...
8
2537
by: Eyeawanda Pondicherry | last post by:
I have put some code together that creates an enum dynamically from some database values. The enum can be read perfectly by an application that references the dynamically generated dll. If I /emit/ a new version of the assembly, and start the application again, the new values will appear for the enum. However, suppose I want the application to remain in a running state.
10
3225
by: moondaddy | last post by:
I'm writing an ecommerce app in asp.net/vb.net and need to make the pages searchable and crawlable by spiders, particularly Google's. As far as I know, if my pages's contents are mostly populated by user controls on a single page and I call these different controls by passing one or more parameters like this: myweb.com/default.aspx?MenuID=44, then the spiders aren't going to be able do to anything with this. asp.net offers lots of great...
4
3803
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was hoping someone could explain how to efficiently build the where clause of a sql string to send to SQL 2000 for a data set. Currenly I check each control with an IF statement to determine if something is filled in. If there is I begin building the where clause. Below is what I have done (and it...
17
4436
by: john | last post by:
All: I'm a long-time developer, new to PHP.... Is there an idiom used in PHP to construct SQL statments from $_POST data? I would guess that in many applications, the data read from $_POST are used to build SQL statements. Certainly, we can do the following:
0
3978
by: jeoffh | last post by:
Background: I am trying to "merge" some attributes into an existing XML column in my MS SQL 2005 database. The general idea is that I have an XML column in a table and I would like to update/delete some values while leaving the other values alone. I am designing this database/table/column so maybe I could use attributes or elements/nodes, the choice is ultimately mine. The one constraint is that I have to allow for customized name/value pairs....
0
9174
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...
0
8884
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...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
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
4376
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
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.