Insert into SQL Db a String That Contain Special Character '

insert into sql db a string that contain special character '

You should be using SqlParameter. http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx

    string query = "insert into ACTIVE.dbo.Workspaces_WsToRefile values(@folderID, @newWorkSpace, @createDate)";

using(SqlCommand cmd = new SqlCommand(query, SqlConnection))
{

SqlParameter param = new SqlParameter("@folderID", folderId);
param.SqlDbType = SqlDbType.Int;
cmd.Parameters.Add(param);
.....
}

Insert query with special characters in sqlite and get that data back SQL

Try String Extension.

extension String {
func base64Encoded() -> String? {
return data(using: .utf8)?.base64EncodedString()
}

func base64Decoded() -> String? {
guard let data = Data(base64Encoded: self) else { return nil }
return String(data: data, encoding: .utf8)
}
}

Try this!!
Just encode the string in base64 and save it in the database and decode it when retrieving it from the database.

Hope this will help you.

How to insert a string with special characters into MySQL?

EncodeForHTML() does not fix this particular issue if you are actually inserting HTML from TinyMCE for example.

What fixed this was changing the Collation to utf8mb4. You can do this in Workbench by expanding the header. It's collapsed by default.

  1. Backup your table.
  2. Go to "Alter Table".
  3. Click the arrows on the top right of the windows Expand the header

  4. Select utf8mb4 from the Collation dropdown.

Change the Collation


  1. Click "Apply"

How to insert special characters in MySQL

Almost all the characters you list can be directly inserted in to a text or char field without problems.

Depending on the quote character you use you only need to "escape" the same character, so when using single quotes ' you don't have to escape double quotes ". With the quote you can either escape it with a back slash \ or double up the character ''.

Back slash characters also need to be escaped or doubled up.

Here's an example of how to handle the different characters: https://www.db-fiddle.com/f/qiV1AsQdRYLZkUE4HAzWgu/1

create table accident_report (id integer, description text);

insert accident_report(id, description) values
(1, '@#$%^&*()_+[{}]|:;"<>,.?/'),
(2, '\\'),
(3, '\''),
(4, '''');

select * from accident_report;

Interestingly the markdown code colouring doesn't quite get it right with the double quoted characters.



Related Topics



Leave a reply



Submit