Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#SQL
i want to select datas from table if they name like a text box tex , for this i write this code
                string str = "Data Source=C:\\Documents and Settings\\almas\\Desktop\\BazarKhodro\\khodro.sdf";
                Qconnection.ConnectionString = str;
                Qcommand.Connection = Qconnection;
 

                string commandText = "select id,name,lname,phone,mobile,address from moshtari where name like '% @name %' and lname like '% @lname %'";
                Qcommand.Parameters.AddWithValue("@name", textBox3.Text);
                Qcommand.Parameters.AddWithValue("@lname", textBox4.Text);
                Qcommand.CommandText = commandText;
                Qcommand.CommandType = CommandType.Text;
                SqlCeDataAdapter a = new SqlCeDataAdapter();
                a.SelectCommand = Qcommand;
                a.Fill(k);
                Qconnection.Open();
                Qconnection.Close();
                return k;
 
but dont work correct also i write the query in sql and dont have error but dont show the result pleas help me
Posted 19-Nov-12 18:43pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi
 
Can you try after removing the blank space between % and @lname ?
 
I.E
 
    string commandText = "select id,name,lname,phone,mobile,address from moshtari where name like '% @name %' and lname like '%@lname%'";
  Permalink  
Comments
f.sarikhani at 20-Nov-12 2:08am
   
thanks this solved my problem
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can try:
 
select id,name,lname,phone,mobile,address from moshtari where name like '%' + @name + ' %' and lname like '% ' + @lname + '%'
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 530
1 OriginalGriff 379
2 Manas Bhardwaj 350
3 Abhinav S 295
4 Sampath Lokuge 255
0 Sergey Alexandrovich Kryukov 7,647
1 OriginalGriff 4,287
2 Peter Leow 3,681
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid