Storing unicode like ✅ from form to db - sql-server

I cannot get unicode characters from form to db
The webdesigner/seo-guy wants to use an unicode character ✅ (9989, which shows up as a whute checkmark in a green box.
The data in the CMS is entered through a form, both a
If I paste the ✅ directly into database, using Mssql SSMS, character is seem in the field, and unicode(field) is 9989.
The asp can retrieve the ✅ and put it as value in the html form.
I post the form, the page shows the form sends the correct code, ✅. the page then post the contents and retrieves it again, but the value stored is not ✅ but "?", char 63.
So DB->form is ok, form->DB is broken.
My page starts with
<% Response.Charset="UTF-8"%>
<% Response.codepage="65001" %>
<form method='post' accept-charset="utf-8">
The field in the db is nvarchar, SQL_Latin1_General_CP1_CI_AI though I tried Danish_Norvegian too, no difference.
edit
I have the insert wrapped in a function, but unwrapped it's like this:
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = connection
cmd.CommandType = 1 ' adCmdText
cmd.CommandText = "update t_kat set meta_title=?,meta_description=? where id=?"
cmd.Parameters.Append cmd.CreateParameter("",adVarChar,1,255, request.form("meta_title"))
cmd.Parameters.Append cmd.CreateParameter("",adVarChar,1,255, request.form("meta_description"))
cmd.Parameters.Append cmd.CreateParameter("",adInteger,1,255, request.form("id")
cmd.Execute
EDIT 2
It works if I say server.htmlencode(request.form("meta_description")) but then ✅æøåÆØÅ gets stored in the db as ✅æøåÆØÅ which I'd rather avoid.
In worst case, id accept the "wierd" characters as &#9989 but I prefer the other characters as-is. But I don't think there is an option to select which characters are replaced.
I could do a replace of each "weird" charactes to %#nnnnformat (I don't think he uses that many) in the CMS frontend before storing, but I'd rather not go there either.

SOLVED!
The parameter should be the right type:
cmd.Parameters.Append cmd.CreateParameter("",adVarWChar,1,255, request.form("meta_title")
adVarWChar instead of adVarChar
I think only quotes are in need of being replaced when using the data in a input text form
<input type='text' name="meta_title" value="<%=replace("""",""",res("meta_title"))%>">
This is to prevent invalid HTML like
<input type="text" value="The 11'8" bridge">
Turning it into <input type="text" value="The 11'8" bridge">
If used as text, the < needs escaping;
<B>one<two</B>

Related

Allow edits from different users appear in different color inside memo box : Microsoft Access 2010

I have a memo field which contains rich text. I am able to identify a user and change all the text in the box instead of just the text they added.
I am looking to write code which allows the text to be edited and after update , the edited text will appear a different color than the original text in the memo field.
I have tried :
Dim strNew As String
Dim strOld As String
If Me.txt_username_id = "grant" Then
strOld = Me.Form!txtnotesaboutproduct1.OldValue.ForeColor = vbBlack<br/>
strNew = Me.Form!txtnotesaboutproduct1.ForeColor = vbRed
End If
I have also tried
Dim ctlOld As TextBox<br/>
Set ctlOld = Me.Form!txtnotesaboutproduct1
If Me.txt_username_id = "grant" Then
ctlOld = Me.Form!txtnotesaboutproduct1.OldValue.ForeColor = vbRed
End If
Generally, I do this with a continuous subform for Notes, so that I can hold the data, date and user, rather than just one formatted text box. Though I do realize this might be a lot more real estate that you might have, you can use a conditional format within the subform. I do agree that if it is possible, you'll likely need to use HTML and not .Forecolor, which will change the entire box.

MS Access Form filter dropdown

Having created a copy of an Access DB Backend in SQL Server, the Access Frontend has stopped showing the "Filter" list when the Filter button is pressed on the main form:
Before:
After:
I'm not sure what is causing this. In the old frontend I am opening the form like this:
Set rs = CurrentDb.OpenRecordset(sSQL)
Where sSQL is like:sSQL= "Select * from [EventReport]"
And in the new version I'm opening the form like this:
Set rs = CurrentDb.OpenRecordset(sSQL, dbOpenDynaset, dbFailOnError + dbSeeChanges)
I'm not sure if any of this is actually relevant to the issue, by any help is appreciated!
Tom
a bit more googling found the answer. In Access Options I needed to turn on the ODBC Fields in the Filter Lookup options for the Current Database

ASP, HTML Input i need to return a value not linked with another field

I have a system within my html holiday booking app which prints out an array of holiday requests which look like so.
For i = 0 To Ubound(arrHolsAccept) Step 1
response.Write("<form action=""AdminGUI.asp"" method=""post"">")
Response.write("<tr>")
Response.write("<td>"& "<input type=""hidden"" name=""HolidayID"" value=" &arrHolsAccept(i,0)& " " & "</td>")
Response.write("<td>"& arrHolsAccept(i,1) &"</td>")
Response.write("<td>"& arrHolsAccept(i,2) &"</td>")
Response.write("<td>"& arrHolsAccept(i,3) &"</td>")
Response.write("<td>"& arrHolsAccept(i,4) &"</td>")
Response.write("<td><input type=""submit"" name=""accepthol"" value=""Accept""/><td/>")
Response.write("<td><input type=""submit"" name=""declinehol"" value=""Decline""/><td/>")
Response.write("</tr>")
response.write("<form/>")
Next
the Issue I am having is that the accept and decline buttons within each array item set that is printed out need to pass a value to the database. which is the holiday ID arrHolsAccept(i,0) how can I get these submit and decline buttons to pass this value to the database connection element?
so far my connection element of the system looks as follows
objDBCommand.Parameters.Append objDBCommand.CreateParameter("#HolidayRef", adVarChar, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("#EmployeeID", adVarChar, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("#jobroleofstaff", adVarChar, adParamInput,200)
objDBCommand("#HolidayRef") = Request.Form("HolidayID")
objDBCommand("#EmployeeID") = Session("userID")
objDBCommand("#jobroleofstaff") = Session("JobroleID")
the submit and decline buttons run this section of code and are supposed to pass it a value. as the array builds the holidays it builds multiple of these submit and decline buttons and I do not know how to differentiate the buttons and then assign the correct holiday ID to them, I have tried multiple things so far and I can't seem to get it to work.
You are already passing the HolidayID / arrHolsAccept(i,0) as a hidden field on this line:
Response.write("<td>"& "<input type=""hidden"" name=""HolidayID"" value=" &arrHolsAccept(i,0)& " " & "</td>")
And you are passing that value to the database stored procedure on this line already:
objDBCommand("#HolidayRef") = Request.Form("HolidayID")
I think the problem you are having is possibly because you are not closing your form. You have an error in your code and need to change this line:
response.write("<form/>")
To:
response.write("</form>")
Put the values of arrHolsAccept(i,1) as the value in a hidden field, comma-separated, then parse it on the server after the form is submitted.

String Encoding Issue

I am having a very weird issue in the way strings get stored in my database, and as a result, I am getting these "unterminated string literal" errors in Javascript.
Here's an overview of what I am doing:
Platform: C#/ASP.NET MVC 1.0, SQL Server 2005, SparkViewEngine, YUI 2
In my view, I serialize an object into a JSON data structure using Json.NET from NewtonSoft.
<script type="text/javascript">
// <![CDATA[
var data = YAHOO.lang.JSON.parse("${Newtonsoft.Json.JsonConvert.Serialize(Model)}");
....
</script>
Normally, this works, but I noticed that one of the fields I pull from the database contains the following data, which causes the string to not be formed properly.
The database field is an NVARCHAR(2000).
For some of the entries, I get these weird characters in the string when I copy and paste from the database to notepad.
Compile ?Analysis ?& ?Recommendations? deck
In Firebug, it shows as a bunch of line breaks:
Analysis & Recommendations deck","StartDate":"1/19/10","FinishDate":"1/26/10","Duration":6.0,"
Compile 
Analysis 
& 
Recommendations
 deck
UPDATE
After talking to the user, I discovered that they were using the copying and pasting from a word document onto the HTML form.
The form itself uses the YUI Connection Manager to make an asynchronous POST call (AJAX) to save the form values.
The database saved the form field value along with any encoding associated with it.
It seems like there are characters in Word that are printable, but not in ASCII. Is there any way to detect this and encode correctly?
This appears to be a case of you not handling the quote characters properly. You have several ways to go. The way I use for comments for our web site is to make sure all quotes are encoded, both single and double, so that both your SQL, ASPX & Javascript won't hiccup.
Our method is for customer comment fields so we're overboard on the conversions.
Function SafeComment(ByVal strInput)
' Renders Any Comment Codes Harmless And Leaves Them HTML readable In An eMail Or Web Page
' Try: SafeComment("`~!##$%^&*()_+=-{}][|\'"";:<>?/.,")
SafeComment = ""
If Len(strInput) = 0 Then Exit Function
SafeComment = Replace(Replace(Replace( _
Replace(Replace(Replace( _
Replace(Replace(Replace( _
Replace(Replace(Replace( _
Server.HtmlEncode(Trim(strInput)), _
"-", "-"), ":", ":"), "|", "|"), _
"`", "`"), "(", "("), ")", ")"), _
"%", "%"), "^", "^"), """", """), _
"/", "/"), "*", "*"), "'", "'")
End Function
It's not pretty, but it does the job.

MS Access - open a form taking a field value from a previous form

I have a form in an MS Access database which lists all the landowners consulted with for a new electricity line. At the end of each row is a button which opens another form, showing the details of all consultation, offers made etc.
I am trying to use vb in MS Access to take the contactID and automatically put it in a field in the details form, so that landowner's consultation details will pop up automatically. I am not a vb programmer at all (I have a comp sci degree mostly in Java and I'm currently working as a GIS analyst but it's a small company so I've been asked to get an Access database working).
I want to say
[detailsForm]![contactID] = [landownerlist]![ID]
in a way that vb and access will be happy with. Then I can see if I'm on the right track and if it will actually work! What I have above does not actually work. It won't compile.
From Kaliana
If you wish to open a form to a new record and to set the ID there, you can use Openargs, an argument of Openform:
DoCmd.OpenForm "FormName",,,,acFormAdd,,Me.ID
The opened form would also need some code:
If Me.Openargs<>vbNullstring Then
Me.Id = Me.Openargs
End If
It is also possible to find:
Forms!LandownersList.Recordset.FindFirst "ID=" & Me.ID
or fill in a value:
Forms!LandownersList!Id = Me.ID
on the form being opened from the calling form.
You may want to look into the code that is behind these buttons. If you are using a docmd.openform you can set the 4th Setting to a where clause on openning the next form.
DoCmd.OpenForm "OpenFormName", acNormal, , "[contactID] = " _
& [detailsForm]![contactID] , acFormEdit, acWindowNormal
This assumes contact ID is numeric and doesn't require any quotes.
Using open args is the generally accepted solution, as alluded to by others. This just falls under the category of "For you edification":) One of the problems with using open args is that unless you are careful with your comments it's easy to forget what they were supposed to mean. Were you passing more than one? Which is which? How did I do it here? How did I do it there etc. For my own money, I standardized to this (below) so I can always pass more than one argument without fear, and when I review my code a year from now, I can still see what's what without a huge hassle:
Option Explicit
'Example use: DoCmd.OpenForm "Example", OpenArgs:="Some Filter|True"
Public Enum eForm1Args
eFilter = 0
eIsSpecial = 1
End Enum
Private m_strArgs() As String
Public Property Get Args(ByVal eForm1Args As eForm1Args) As String
Args = m_strArgs(eForm1Args)
End Property
Private Sub Form_Open(Cancel As Integer)
m_strArgs = Split(Nz(Me.OpenArgs, vbNullString), "|")
If LenB(Me.Args(eFilter)) Then Me.Filter = Me.Args(eFilter)
End Sub
Private Sub Command1_Click()
If LCase$(Me.Args(eIsSpecial)) = "true" Then
'Do something special
End If
End Sub
As previously posted OpenArgs is great for this. One trick I have learned is that it is easy to pass in multiple parameters if required as a delimited string (comma for example), the target form can then access these values using the Split() function thus:
StringArrayVariable()= Split(me.OpenArgs,",")
Me.textbox= StringArrayVariable(0)
Me.textbox1= StringArrayVariable(1)
etc.
This is air code so check out the helpfile for Split().
It is also possible to pass objects in OpenArgs as well, it requires some manual memory pointer manipulation and I don't have the code to hand but I'm sure a Google search will find some examples. This technique can cause some random crashes though. Be Warned!

Resources