Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a database application in c# with sql. i have about 30 fields. i want create a search field where i can search records from my database. i want my search field to be include combobox and textbox and button. the combobox should include all my fields , so that when i enter a text in the textbox it will search based on the field in the combobox
pLS i NEED HELP
Posted
Comments
OriginalGriff 9-Jul-14 3:11am    
What help?
What have you tried?
Where are you stuck?
What help do you need?
Remember, we can't see your screen, access your HDD, or read your mind - we only get exactly what you tell us.
Use the "Improve question" widget to edit your question and provide better information.

You should use dynamic sql query for that.. :)
like this,

SQL
declare @StrQuery nvarchar(max),@columnName varchar(150),@searchText nvarchar(max)
 select @StrQuery='select * from tableName where '+@columnName+' like ''%' + @searchText+ '%'''
 exec(@StrQuery)


where @columnName has been passed from code behind from combobox and @searchText has been passed from textbox from code behind.. :)
 
Share this answer
 
put this coding to form load


con.Open();
cmd = new SqlCommand("select Eid,Ename from temp order by Eid asc",con);
cmd.CommandType = CommandType.Text;
dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
while (dr.Read())
name.Add(dr["Eid"].ToString());


con.Close();

textBox4.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox4.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox4.AutoCompleteCustomSource = name;
}
 
Share this answer
 
Comments
Nirav Prabtani 9-Jul-14 3:29am    
This is solution is for what ???
Member 10918596 9-Jul-14 3:32am    
auto textcomplete search...
Nirav Prabtani 9-Jul-14 3:35am    
Read question carefully, Your solution is not match with requirement...
MaximusDebois 9-Jul-14 3:38am    
the issue is that i have a combobox , textbox and button when i select an item from the combobox and type in something in the textbox and press the button, it is suppose to search for records in the database.Pls any help on this issue

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