I think it's better to explain some thing about it:
when you type only a word like"windowsForm" in search Textbox with this Query it must shows all of documents that included this word and show it in listview but it doesn't work
PLZ Help
9 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 19, 2009, 4:10 AM EDT
✓ Accepted answer0
Hi Dear
Take a Look at The Link below It Will help you to refer Queries :)
Maharaje124 reputationPosted Aug 18, 2009, 5:24 PM EDT
0
Hi
i think you are right i forgot to say that this search isn't in the DB it is about all of your system(Folders, Drives,...) ?! I have Problem with this i need the answer for it
Maharaje124 reputationPosted Aug 18, 2009, 9:36 PM EDT
0
i have this error:Object reference not set to an instance of an object.
on this line :
foreach (DataRow rw in dt.Select("note like '%" + textBox1.Text.Trim() + "%'"))
when i type only one char
WHERE FREETEXT('You Text for Best Match')or You can Use
WHERE FREETEXT(FileName, ' maharaje ')orWHERE FileName LIKE'%test%' // It Will resturn all the File Name which contain 'test' word
and for that Error You are getting is Not Seems under My Provided Project Files In Above post take a look at it :)
Happy Coding :) in Select("note ....) "note" is a column name i have in my data table that i filled from database . may be you dont have the same column name becase you are using Indexing Service
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 19, 2009, 4:10 AM EDT
Take a Look at The Link below It Will help you to refer Queries :)
http://www.codeproject.com/KB/database/Indexing_Service_HOW-TO.aspx
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 18, 2009, 4:08 AM EDT
I have Coded the Functionality
you need It Will Search As You Type in Text Box and Display result in DataGridView ( Here i used gridview instead of
ListView but you can use ListView also :)
Included Project Files Take a Look at it Link is At below of the post and if any problem let me know
namespace LiveSearchSample
{
public partial class Form1 : Form
{
DataView dv;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select * from users",con);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
dv = new DataView();
//Set DataView to DataTable
dv = dt.DefaultView;
//Show DataView in DataGridView
dataGridView1.DataSource = dv;
con.Close();
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
string SearchText = txtSearch.Text.Trim();
//Live Search Code
dv.RowFilter = "Username like '" + SearchText + "%'";
}
}
}
Maharaje124 reputationPosted Aug 18, 2009, 5:24 PM EDT
i think you are right i forgot to say that this search isn't in the DB it is about all of your system(Folders, Drives,...) ?! I have Problem with this i need the answer for it
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 18, 2009, 7:28 PM EDT
You Can Still Perform this Because you can Build a DataTable From The list of Files you have and then
Use That dv.RowFilter :) still if you need assistance i am here to help you out :)
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 18, 2009, 8:20 PM EDT
Indexing Search Here I have Filled my datatable with from database but you can build DataTable from your custom
data in coding also :) Add All your Drives / Folders Etc in DataTable and Display ListView From that Datatable and
Search on it :)
namespace LiveSearchSample
{
public partial class Form1 : Form
{
DataView dv;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// You can Also Construct Datatable With Whatever Data it is weather its in database or Not :)
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select * from Reminder",con);
SqlDataAdapter da = new SqlDataAdapter(comm);
dt = new DataTable();
da.Fill(dt);
//Here the main Process Starts
foreach (DataRow rw in dt.Rows)
{
string[] u = new string[2];
u[0] = rw[0].ToString();
u[1] = rw[1].ToString();
listView1.Items.Add(new ListViewItem(u));
}
con.Close();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text.Trim() != "")
{
listView1.Items.Clear();
foreach (DataRow rw in dt.Select("note like '%"+textBox2.Text.Trim()+"%'"))
{
string[] u = new string[2];
u[0] = rw[0].ToString();
u[1] = rw[1].ToString();
listView1.Items.Add(new ListViewItem(u));
}
}
else
{
listView1.Items.Clear();
foreach (DataRow rw in dt.Rows)
{
string[] u = new string[2];
u[0] = rw[0].ToString();
u[1] = rw[1].ToString();
listView1.Items.Add(new ListViewItem(u));
}
}
}
}
}
Maharaje124 reputationPosted Aug 18, 2009, 9:25 PM EDT
Maharaje124 reputationPosted Aug 18, 2009, 9:36 PM EDT
on this line :
foreach (DataRow rw in dt.Select("note like '%" + textBox1.Text.Trim() + "%'"))
when i type only one char
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 18, 2009, 9:45 PM EDT
Your Query Having Mistake i think
Where like below
WHERE FREETEXT('You Text for Best Match') or You can Use WHERE FREETEXT(FileName, ' maharaje ') or WHERE FileName LIKE '%test%' // It Will resturn all the File Name which contain 'test' wordHappy Coding :) in Select("note ....) "note" is a column name i have in my data table that i filled from database . may be you dont have the same column name becase you are using Indexing Service
Maharaje124 reputationPosted Aug 19, 2009, 1:56 AM EDT