Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
ALTER PROCEDURE dbo.search_and_and
	 @fname varchar(35),
	 @lname varchar(35)
	-- @city_id int
AS
	Begin
	select registration.user_id as 'Id' ,registration.sname as 'Name',
	 registration.fname as 'First Name', registration.mname as 'Middle Name', registration.lname as 'Last Name', registration.address as 'Address',
	  city.city_name as 'City', state.state_name as 'State',registration.bdate as 'Bdate',registration.gotra as 'Gotra', 
	  registration.pincode as 'Pincode', registration.occupation as 'Occupation', registration.membership as 'Membership', 
	  registration.blood_id as 'Blood Group' from registration inner join city 
	  ON registration.city_id = city.city_id inner join state 
	  ON registration.state_id = state.state_id AND city.state_id = state.state_id 
	  WHERE (registration.fname =@fname) AND (registration.lname = @lname) --AND registration.city_id = @city_id
	End
	RETURN


dis is my code to search according to firstname and lastname

SQL
if (select1 == "AND" && select2 == "AND")
           {

  cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@fname", cmbmemfname.SelectedText.Trim());
                cmd.Parameters.AddWithValue("@lname", cmbmemlname.SelectedText);
             //   cmd.Parameters.AddWithValue("@city_id", cmbmemcity.SelectedValue);
                SqlDataAdapter memfnameda = new SqlDataAdapter(cmd);
                DataTable memfnamedt = new DataTable();
                memfnameda.Fill(memfnamedt);
                dgridregistration.DataSource = memfnamedt;



this is my code to search.

and
C#
SqlDataAdapter fnameda = new SqlDataAdapter(" select fname,user_id from registration", con);
               DataTable fnamedt = new DataTable();
               cmbmemfname.DataSource = fnamedt;
               fnameda.Fill(fnamedt);
               cmbmemfname.DisplayMember = "fname";
               cmbmemfname.ValueMember = "user_id";
               cmbmemfname.DropDownStyle = ComboBoxStyle.DropDownList;


and the above code to fill the combobox which have firstname

i have tested this query this is ok. but when i leave a space before firstname.

but i don't understand why dis is so.

i also tried '' + @fname in sql query. but this is also not working
Posted
Updated 9-Jun-14 2:35am
v2
Comments
ZurdoDev 9-Jun-14 8:26am    
I don't understand the problem.
Member 9671810 9-Jun-14 8:29am    
sir. the query is not working.
i don't understand what is the problem.
Thanks7872 9-Jun-14 8:37am    
I don't see any code to call the stored procedure you have mentioned.
Member 9671810 9-Jun-14 8:43am    
i have mentioned look above. but 1 line is missing over here.
SqlCommand cmd = new SqlCommand("search_and_and", con);

1 solution

The equals test looks for an exact match, not a "a bit like this" match.
Try this instead:
SQL
... WHERE (registration.fname LIKE '%' + @fname + '%') AND ...
In this case, the '%' character is a wildcard: "match zero or more of anything"
 
Share this answer
 
Comments
Member 9671810 9-Jun-14 10:14am    
Sir. still the same not showing any records.

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