问题描述
我想根据在搜索文本框中传递的字符在datagridview中导航记录.
例如,如果我输入一个字符"s",则记录应从datagrid视图中的s开始.我在运行查询时遇到问题,我编写了以下代码,但运行不正常.
请提示我我的语法错误或查询?或修改此代码.请进行一些更改
I want to navigate records in datagridview according to the character that passed in the searching text box.
For example if i enter a character ''s'' the records should be started from s in datagrid view. I''m facing problem while running query i write the following code but it is not working well.
Please suggest me is my syntax wrong or query? or modify this code. Please do some changes
string s;
private void button1_Click(object sender, EventArgs e)
{
s = textBox1.Text;
OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=d:/passangerdb.mdb");
con.Open();
// MessageBox.Show("connected");
OleDbDataAdapter da = new OleDbDataAdapter("Select p_name,id_no,rout,d_o_b from passager where p_name like''s%'' ", con);
DataSet ds = new DataSet();
da.Fill(ds, "passager");
int x = 0;
x = ds.Tables["passager"].Rows.Count;
if (x == 0)
{
MessageBox.Show("no person exist with this name" + textBox1.Text);
}
else
{
dataGridView1.DataSource = ds.Tables["passager"];
}
con.Close();
}
推荐答案
我在面对问题时运行查询时,我编写了以下代码,但运行不正常.
I''m facing problem while running query i write the following code but it is not working well.
什么意思?任何错误消息?
像这样尝试
What do you mean? any error message?
Try like these
OleDbDataAdapter da = new OleDbDataAdapter("Select p_name,id_no,rout,d_o_b from passager where p_name like''" + s + "%''", con);
或
or
OleDbDataAdapter da = new OleDbDataAdapter("Select p_name,id_no,rout,d_o_b from passager where p_name like''" + textBox1.Text + "%''", con);
这篇关于在datagridview中记录导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!