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.
- Backup your table.
- Go to "Alter Table".
Click the arrows on the top right of the windows
Select utf8mb4 from the Collation dropdown.
- 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
Which Linux Distribution Is Best for Developing a Mono Application in a Virtual Machine
Error While Using Executenonquery C#
C# Call C++ Dll Passing Pointer-To-Pointer Argument
Change the Bordercolor of the Textbox
Ruby Equivalent of C# 'Using' Statement
Directory.Getcurrentdirectory() Not Working on Linux
C# Task.Waitall() in .Net and Mono
JavaScript Serialization of Datetime in ASP.NET Is Not Giving a JavaScript Date Object
Visual Studio C# Intellisense Not Automatically Displaying
Convert Utc Datetime to Another Time Zone
Is There a Linux Equivalent of Dllimport in .Net Core
Windows Form Application Exception
Is C# Really Slower Than Say C++
ASP.NET MVC 4 + Ninject MVC 3 = No Parameterless Constructor Defined for This Object
How to Call R Functions from C# and Retrieve The Result in C#
Soap Authentication Fails When Running a C# App on a Linux Box