I have some data stored in SQL Server that contains apostrophes. Within the SQL Server table to apostrophe is escaped. For example the phrase “Roberts’s thesis” is stored as “Robert”s Thesis”. I use Access 2003 as a font end for the application and I use ADO to access the data stored in SQL Server using Stored Procedures.
The issue I am having is how to “un-escape” the double apostrophe when the data is retrieved using a recordset and then bound to a control. Here is some sample code.
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.ConnectionString = myConnectionString
cnn.Open
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = cnn
rs.Source = "EXEC uspMyStoredProcedureName"
rs.LockType = adLockOptimistic
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.Open
Set ListControl.Recordset = rs
Set rs = Nothing
Set cnn = Nothing
Do I have to “loop” through the recordset manually and un-escape the apostrophe? Thank you.
You don’t have to unescape anything. The doubled-apostrophe form is only used for string literals inside SQL statements. The actual value inserted in the database by
INSERT... 'Robert''s Thesis';isRobert's Thesis, and that is the value you’ll get out when you read it from a recordset grabbed from aSELECT.If whatever’s inside
uspMyStoredProcedureNameis doing something weird to cause doubled apostrophes to get returned then it’s broken and needs fixing; if you haveRobert''s Thesisas an actual value in the database, then you’ve inserted broken data and you should be looking at fixing the code that’s done that, and cleaning up the data.