Click here to Skip to main content
15,917,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am able to store special characters in SQL thanks to original Griff. But when I am trying to read data I am facing problem With that special characters. The data contain normal data with some "'" character. because of that I am unable to display that data in drop down and others.

What I have tried:

I googled but unable to get suitable result.
Posted
Updated 25-Aug-17 22:45pm
v2
Comments
OriginalGriff 26-Aug-17 3:29am    
What problem?
When? How does it manifest? What code are you using that shows the problem?
What have you done to find out what the problem is?
vijay_bale 26-Aug-17 4:14am    
This is my code to display that names in dropdown.
string que = "SELECT compname FROM companyDB ";
string query = "SELECT compname FROM companyDB";
string quer= "SELECT catname FROM catDB";
string qu="SELECT catname FROM catDB";
SqlDataAdapter da = new SqlDataAdapter(que, con);
SqlDataAdapter sda = new SqlDataAdapter(query, con);
SqlDataAdapter dp = new SqlDataAdapter(quer, con);
SqlDataAdapter sdp = new SqlDataAdapter(qu, con);

DataSet ds = new DataSet();
DataSet sds = new DataSet();
DataSet de = new DataSet();
DataSet sde = new DataSet();

da.Fill(ds, "companyDB");
sda.Fill(sds, "companyDB");
dp.Fill(de, "catDB");
sdp.Fill(sde, "catDB");

combocomp.DisplayMember = "compname";
combocomp.ValueMember = "compname";
combocomp.DataSource = ds.Tables["companyDB"];

comboncomp.DisplayMember = "compname";
comboncomp.ValueMember = "compname";
comboncomp.DataSource = sds.Tables["companyDB"];

combocat.DisplayMember = "catname";
combocat.ValueMember = "catname";
combocat.DataSource = de.Tables["catDB"];

comboncat.DisplayMember = "catname";
comboncat.ValueMember = "catname";
comboncat.DataSource = sde.Tables["catDB"];

combocomp.SelectedIndex = -1;
comboncomp.SelectedIndex = -1;
combocat.SelectedIndex = -1;
comboncat.SelectedIndex = -1;
if special character is there in companyDB or catDB, then it is showing some thing like system . like that. If I remove special character from there every thing is coming perfectly

In drop down It is showing now.I created there for testing purpose in CompanyDB son's.
now i came where i am calling that as a drop down, there it is showing son's. If i select that, error is coming that incorrect syntax near s.

1 solution

Quote:
if special character is there in companyDB or catDB, then it is showing some thing like system . like that. If I remove special character from there every thing is coming perfectly

That's because DisplayMember and ValueMember use Properties to access the actual data in the data source - which means that the string you pass to to them must be than name of a valid property in C#. So it has to follow the C# rules for variable names, which do not include special characters.

I think you have made some terrible decisions here: it looks like you have a separate table for each company, and that's a very, very bad idea. Keep them data together, and use a separate table to contain all company names, with an ID value in your main table:
Companies:
ID      Name           Address     ....
1       Bob's Bakers   ...
2       Mike-the-Bike  ...

Purchases:
ID      CompId         Date        ItemID      Price    ....
1       1              2017-02-14  77123 ...
2       1              2017-02-15  78554 ...
3       2              2017-02-15  65882 ...
Then you pull out what you need from that using WHERE clauses (and JOINs as applicable). Keeping separate tables for each company is just ridiculous - what if two companies have the same name? You can't have two tables with the same name!
 
Share this answer
 
Comments
vijay_bale 26-Aug-17 5:27am    
that is only one company, one category.companyDB for company and catDB for category.Example Unilever I am storing in companyDB, toilet soaps is a category I am storing in CatDB.Here I am displaying companyDB and catDB both for two times one for create brand and second for editing existing brand purpose. means user can move that brand for one company to other company and user can change the category also.


Here I am posting a View
http://imgur.com/a/jBTRk

Here Screenshot of that error
http://imgur.com/L4qjgch

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