Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Data already saved to access db templates_table.finalcontent as "Hi " + Trim(Me.txtClientName.Text) + vbCrLf + "We wishes a prosperous happy new year to you. -" + Trim(Me.txtFirmName.Text)

I have fetched data to "FinalStuff" variable

FinalStuff = "Hi " + Trim(Me.txtClientName.Text) + vbCrLf + "We wishes a prosperous happy new year to you. -" + Trim(Me.txtFirmName.Text)

But my problem is, its not working as a vb.net code.
How to convert "FinalStuff" as a vb.net code?

What I have tried:

Dim FinalStuff = ""
Using MyConnection As OleDb.OleDbConnection = GetConnection(),
    MyCommand As New OleDb.OleDbCommand("Select finalcontent From templates_table", MyConnection)
    If MyConnection.State = ConnectionState.Closed Then MyConnection.Open()
    Using MyDataReader As OleDb.OleDbDataReader = MyCommand.ExecuteReader
        While MyDataReader.Read
            FinalStuff = MyDataReader("finalcontent")
        End While
    End Using
End Using
Posted
Updated 4-Jan-22 3:20am
v2
Comments
CHill60 4-Jan-22 7:44am    
"not working" is one of the most uninformative phrases we hear. What happens (or doesn't happen). What has the code FinalStuff = "Hi " .. etc got to do with extracting FinalStuff from the database? Which bit is not working?
Venu Gopal Mulavana Kayamkulam 4-Jan-22 7:53am    
Its remains as the same text. I need in the result, instead of Trim(Me.txtClientName.Text) ther should b the input value of Me.txtClientName.Text. Its a textbox in the form and that has a value also.
CHill60 4-Jan-22 8:02am    
You are still not making yourself clear. That first line of the highlighted code should read
Dim FinalStuff As String = ""
- is that what you mean?
0x01AA 4-Jan-22 9:14am    
My very wild guess is, that OP expects, that e.g. Trim(Me.txtClientName.Text) will be (miracle wise) replaced by the text from a textbox on his form... in a way as if he would 'execute' the string read from the database as VB code.

1 solution

Pretty much, you can't - or at least not in a sensible way that will be easy to maintain.
The problem is that you are trying to compile code into an existing and indeed running app and that always a pretty bad idea. Not to mention that it leaves your app (and indeed whole computer) at the mercy of whatever gets stuffed into your DB ...

Basically, what you are trying to do is a mailmerge - so instead of faffing around trying to compile stuff, do what mailmerge programs do: add "merge fields" to the basic letter and then write code to replace them with the actual fields.

In fact, you could use "Trim(Me.xxx)" and "vbCrLf" as text strings as your "merge field" identifiers (though there are generally better options such as "%*ClientName*%", %*CompanyName*% as it's trivial to pick out the stuff between "%*" and "*%"), then use string.Replace to fill in the user details.

It's a lot easier to do that than to mess around trying to compile into an existing app, honestly! And a whole load less risky ...
 
Share this answer
 
Comments
Venu Gopal Mulavana Kayamkulam 5-Jan-22 1:28am    
done with as per u mentioned string.Replace... thank you very much (Y)
OriginalGriff 5-Jan-22 2:03am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900