Click here to Skip to main content
16,016,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
       }
Posted
Updated 3-Jul-11 4:12am
v2

1 solution

OP wrote:
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);
 
Share this answer
 

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