ChrisN
New member
This is my first post so hope I get it right, and hoping someone can help me
The part of my application I am having a problem with is a mail merge function that replaces pre-defined text in a string with data from a SQL Database.
This function is used for sending out personalised emails, account information, customizing data on a web page etc.
I want to take text from a pre-defined template.
I.E. DataStr = "Thank you [FirstName] for using our service."
Step one:
Get the users first name from the database by using information stored in the Mailmerge Table of database.
In the MailMerge table there are two fields MergeCode and MergeData
MergeCode has the code to match the string in the replace function [FirstName]. The MergeData stores a comer delimited string to find the correct piece of data in the database.
MergeData = DBTable,RetrieveField,KeyField,MatchString
It looks like this Users,FirstName,ID,UserID
I then split the data from the MergeData into an array called TableStr = Split(DR("MergeData"), ";", -1, CompareMethod.Text)
This gives me an array with 5 elements
TableStr(0) = "Users"
TableStr(1) = "FirstName"
TableStr(2) = "ID"
TableStr(3) = "UserID"
So the Database Select Command is built like this.
ReturnStr = "Select " & TableStr(2) & "," & TableStr(1) & " from " & TableStr(0) & " where " & TableStr(2) & "=" & TableStr(3))
When I view this string all works except TableStr(3) "UserID"
Select ID,FirstName from Users where ID=? & UserID
Here is the problem. I have a global variable UserID that is populated with a User Number when the user logs on, for this scenario let?s make that UserID = 100
So I want the SQL string to be "Select UserID,FirstName from Users where ID=" 100
But it comes out as "Select UserID,FirstName from Users where ID=" UserID
I am sure there is a simple answer for this but I just can't seem to find it.
Other Information
I am using Visual Studio 2010 Ultimate
Building a web site asp.net using vb.net
This is code behind issue
Thanks in advance
Chris
The part of my application I am having a problem with is a mail merge function that replaces pre-defined text in a string with data from a SQL Database.
This function is used for sending out personalised emails, account information, customizing data on a web page etc.
I want to take text from a pre-defined template.
I.E. DataStr = "Thank you [FirstName] for using our service."
Step one:
Get the users first name from the database by using information stored in the Mailmerge Table of database.
In the MailMerge table there are two fields MergeCode and MergeData
MergeCode has the code to match the string in the replace function [FirstName]. The MergeData stores a comer delimited string to find the correct piece of data in the database.
MergeData = DBTable,RetrieveField,KeyField,MatchString
It looks like this Users,FirstName,ID,UserID
I then split the data from the MergeData into an array called TableStr = Split(DR("MergeData"), ";", -1, CompareMethod.Text)
This gives me an array with 5 elements
TableStr(0) = "Users"
TableStr(1) = "FirstName"
TableStr(2) = "ID"
TableStr(3) = "UserID"
So the Database Select Command is built like this.
ReturnStr = "Select " & TableStr(2) & "," & TableStr(1) & " from " & TableStr(0) & " where " & TableStr(2) & "=" & TableStr(3))
When I view this string all works except TableStr(3) "UserID"
Select ID,FirstName from Users where ID=? & UserID
Here is the problem. I have a global variable UserID that is populated with a User Number when the user logs on, for this scenario let?s make that UserID = 100
So I want the SQL string to be "Select UserID,FirstName from Users where ID=" 100
But it comes out as "Select UserID,FirstName from Users where ID=" UserID
I am sure there is a simple answer for this but I just can't seem to find it.
Other Information
I am using Visual Studio 2010 Ultimate
Building a web site asp.net using vb.net
This is code behind issue
Thanks in advance
Chris
Last edited: