使用实时搜索 [英] Using Realtime search

查看:53
本文介绍了使用实时搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是一个初学者,
想知道如何将Gridview与MS ACCESS一起用于实时搜索
喜欢

I am just a beginner,
Want to know how can I use gridview with MS ACCESS for realtime search
Like

select*From Source where desc like '%textSrch.text%


例如.

我尝试获取数据,但没有删除它要添加的行数.

帮助


as an example.

I tried to get the data, but instead of deleting the number of rows it is adding.

Help

推荐答案

进行过滤的一种方法是从数据库中重新填充基础数据.但是,根据情况,这可能既浪费时间又消耗资源.

其他可能性例如:

例如,如果使用BindingSource,则可以对其应用过滤器.这样,数据保持不变,但仅显示相关部分.有关更多信息,请参见: BindingSource.Filter属性 [ ^ ]

如果您从数据库中将数据提取到DataTable中,则可以定义DataView,该DataView可以过滤DataTable中所需的行,并将该视图作为数据源分配给网格等.更多信息:DataView.RowFilter属性 [ DataColumn.Expression属性 [ ^ ]
One way to do the filtering is to repopulate the underlying data from the database. However, depending on the situation this may be both time and resource consuming.

Other possibilities are for example:

If you''re using for example BindingSource, you can apply a filter on it. This way the data remains the same but only the relevant portion is shown. For more information, see: BindingSource.Filter Property [^]

If you fetch the data into a DataTable from the database you can define a DataView which filters the desired rows from your DataTable and assign that view as your datasource to a grid etc. More information: DataView.RowFilter Property [^]

The expressions you can use are listed in DataColumn.Expression Property [^]


使用以下代码在网格视图中填充搜索结果:

Populate the search result in grid view using the below code:

protected void Page_Load(object sender, EventArgs e)
{
string strSQLconnection = "Data Source=dbServer;Initial Catalog=testDB;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
SqlCommand sqlCommand = new SqlCommand("select * From Source where desc like '%textSrch.text%'", sqlConnection);
sqlConnection.Open(); 

SqlDataReader reader = sqlCommand.ExecuteReader();       

GridView1.DataSource = reader;
GridView1.DataBind();
}


感谢您的帮助,
没什么难的,我自己用这个做的
Thanx for helping,
It was not much hard, I did by self using this
private void textBox1_TextChanged(object sender, EventArgs e)
{
 Conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Database.mdb";
            string txt;
            txt = "%" + textBox1.Text + "%";
            string query = "Select keys, desc from source where desc like '"+txt+"'";
            OleDbDataAdapter da = new OleDbDataAdapter(query, Conn);
            
            OleDbCommandBuilder cmd = new OleDbCommandBuilder(da);
            DataTable dt = new DataTable();
            da.Update(dt);
            da.Fill(dt);

            BindingSource bn = new BindingSource();
            bn.DataSource = dt;

            dataGridView1.DataSource = bn;
}



一切正常...



and it is working fine...


这篇关于使用实时搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆