Click here to Skip to main content
15,891,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I used those link to write the following code:

C#
private void search_Click(object sender, EventArgs e)
{
      string queryString = "SELECT * FROM account WHERE id='1' ";
      OleDbCommand command = new OleDbCommand(queryString, vcon);
      //command.Parameters.Add("id", OleDbType.Char, 3).Value = "1";
      OleDbDataReader reader = command.ExecuteReader();

}


But These code can't help me to display selected row in datagridview.
Maybe I'm don't understand you. Let me details to know you.
I had also performed search all data in datagridview by the following code:

C#
 private void button10_Click(object sender, EventArgs e)
 {
       string vsql = "select * from account";
       OleDbCommand vcom = new OleDbCommand(vsql, vcon);
       DataSet vds = new DataSet();
       OleDbDataAdapter vda = new OleDbDataAdapter(vcom);
       vda.Fill(vds, "res");
       dataGridView1.DataSource = vds.Tables["res"];
       vda.Dispose();
       vcom.Dispose();
}


But I can't preform to search selected row by the first above following code.
please help me.
Posted
Updated 28-Dec-11 21:28pm
v4
Comments
Wendelius 28-Dec-11 15:16pm    
Pre tags added

If this is forms, have a look at this brief description: How to: Bind Data to the Windows Forms DataGridView Control[^]

For the future, don't use literals (1) in your SQL statements, instead use SqlParameter[^]
 
Share this answer
 
Comments
Member 8454009 28-Dec-11 15:57pm    
Sorry, this link is for SqlDataAdaptar. But my problem that means I had used OleDataAdaptar by the following code

using System.Data.OleDb;

OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\db1.mdb");
Wendelius 28-Dec-11 16:03pm    
Ok, the same applies with OleDb, just a bit different class, see: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter.aspx[^]
Check if this helps, Only display first row in GridView[^]
 
Share this answer
 
At last I get a solution how to display selected row data in listview or datagridview. Here I used listview to display and used a textbox for compare data with access database and also a button to search.

C#
private void button_Click(object sender, EventArgs e)
{

    DataTable dt = new DataTable();
    DataSet ds = new DataSet();  
    ds.Tables.Add(dt);
    OleDbDataAdapter da = new OleDbDataAdapter("select * from table", vcon);  // vcon is connection with database
    da.Fill(dt);


    foreach (DataRow myRow in dt.Rows)
    {
        for (int x = 0; x         {
            string name = dt.Rows[x].ItemArray.GetValue(1).ToString();

            if (name == textbox1.text)   // here you can compare your access data with textbox
            {
                MessageBox.Show("Found");
            }
            else
            {
                MessageBox.Show("No");
            }
        }
    }
}


Hopefully it would be really greateful solution. Thanks to all.
 
Share this answer
 
Use Dynamic Grid to display
 
Share this answer
 
Comments
Member 8454009 29-Dec-11 3:52am    
But how
Member 8454009 29-Dec-11 8:45am    
Actually I am not expert in C#. Please known to me, how to use dynamic grid to display selecting row?

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