Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an patient report database, some of their values have database query constants like ' or " so i tried to insert these values using parameters. input was in English but when trying to retrieve the stored value it was returning a value of some kind of binary. the link for pictures and complete code are below.

Picture of value entered from my application : App[^]

Picture of Stored Value in Access : Access.PNG - Google Drive[^]
Picture of Design View in Access : DesignView.PNG - Google Drive[^]
DataGridview from my application : DV.PNG - Google Drive[^]

Complete code in txt : Code.txt - Google Drive[^]

What I have tried:

I used string.format in command text to store values. I can't store some values that have symbols like ' or " using this method. so i choose parameters. But they storing these values in chinese or other like that. I had also tried to set the oledbdata type to VarWChar and other Char types. Nothing worked.
Posted
Updated 30-May-16 22:21pm

1 solution

:sigh:
Given that you have heard of parameterized queries, but you misuse them to store only those fields that give you a problem right now - and then you wonder why they don't work...
Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead - and that includes String.Format which is just string concatenation under a different name!
So... stop doing that, and use parameterised queries throughout. If you don't, you whole database is going to be deleted one day...

Secondly, the data you are inserting to the ImageN fields is binary data - you fetch it as a Byte array - so when you read it back from your DB, it's still going to be binary data, not a string you can read. Yes, it might look like chinese, or Persian, or Korean, or a mix of the three. It's binary data, not a string - and you can't treat it like a string. But you don't show exactly where you read them back, so I can't tell what you are doing with it!
Read it back as binary data, convert it to an Image, and use it as an Image. Don;t use strings in any way, or you will get bad data in your Images.
 
Share this answer
 
Comments
Devil7DK 31-May-16 6:24am    
You are right i am storing the imageN datas as binary, and also using them as binary. But i store Diagnostics data as 'Long Text' But it also showing an binary data. That's my problem.
OriginalGriff 31-May-16 6:31am    
And what type is it in the DB?
Devil7DK 31-May-16 7:29am    
Long Text - Shown in Access.PNG Image on Question

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