Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I'm beginner in C# programming
I'm writeing the program: a arabic to persian Dictionary!
in my form I have a text box that take Arabic text an search it in my SQL Database
my table in Database contains of 3 column:
"arabicDictionary:nvarchar"
"farsiDictionary:nvarchar"
"voice:varbinary(max)"
I wrote my search like this:


C#
private void toolStripButton4_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=.;database=MyDictionary;integrated security = true");
            SqlDataAdapter DA = new SqlDataAdapter();
            DataSet DS = new DataSet();
            try
            {
                DA.SelectCommand = new SqlCommand();
                DA.SelectCommand.Connection = con;
                DA.SelectCommand.CommandText =
                    "SELECT *From Dictable where ArabicDictionary = " + searchText.Text;
                   
                con.Open();
                DA.Fill(DS, "Dictable");
                con.Close();
                dataGridView1.AutoGenerateColumns = true;
                dataGridView1.DataSource = DS;
                dataGridView1.DataMember = "Dictable";
                DA = null;
                con = null;
            
            }
            catch (Exception ex)
            {
                MessageBox.Show (ex.Message);
            }
        }

-----------------
but it dosent work!!!!
it errors"invalid column nam"!!!
I think It's beacause I should write a code that support Arabic but I dont know how Do it :-(
please help me
thanks :)
Posted
Updated 18-Aug-12 2:16am
v4
Comments
[no name] 18-Aug-12 8:18am    
"It's beacause I should write a code"... no it's because of "SELECT *From Dictable where ArabicDictionary". "*From" is not in your database. Try adding a space, "* FROM".
pegah67 18-Aug-12 8:26am    
thanks for your Guidance but it dosent work yet!

You Should Write the specific column name.
If You want all of the columns so write them all one by one.
 
Share this answer
 
Comments
pegah67 18-Aug-12 11:10am    
thanks MR.tolouee!!
my form connect to my SQL and even show the hearers of my column but it dosent show datas!!!!
should i write any code tha change the input text but and later compare it with my data in SQL? I say that beacause my input is in arabic and show it mean that is persian!!!!!
[no name] 18-Aug-12 11:28am    
Reading Data And Binding to Controls by this way it is not such professional choice.
I suggest to add a DataSet and bind your GridView and use BindingSource.Filter to filter it.
Things are going to be easiest.
pegah67 21-Aug-12 3:24am    
thanks MR.tolouee I'l Test it :)
[no name] 21-Aug-12 3:37am    
So why did you reject it?
You're welcome, we are here to help.
pegah67 22-Aug-12 2:53am    
sorry I Not concentrate!
As already said, always define the column names in your query.

But another thing: Never concatenate values to your queries directly. This leaves you open to possible SQL injections, data type conversion problems and so on. Instead use SqlParameter[^]

Addition:

An excellent cartoon suggested and appropriate for this situation :)

http://xkcd.com/327/[^]
 
Share this answer
 
v2
Comments
Espen Harlinn 19-Aug-12 8:36am    
Good point :-D
Feel free to add this to your answer, it kind of gets the point across http://xkcd.com/327/
Wendelius 21-Aug-12 1:05am    
That was a great idea, added. Thanks :-D
I think it should be like

where ArabicDictionary = N'" + searchText.Text + "'";
 
Share this answer
 
Comments
pegah67 22-Aug-12 2:54am    
thanks!

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