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

问题描述

我只是一个初学者,
想知道如何将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

推荐答案


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();
}


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...


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

09-14 10:21