Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guyz,

i have 2 data grid view naming excelGV and sqlGV both are visible on the same form.
one is connected from excel and the other is from sql server..

in excelGV there are 3 columns sno, name and fone no.
On double click event on excelGV it saves the sno of the selected row.

Now i want the data to be searched against the sno in sqlGV..


Thanks..

Updated..

C#
private void BindGridForExcel()
        {
            try
            {
                OleDbConnection theConnection = new OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;data source=D:\\DotNet\\Copy of Depreciation working Oct-13.xlsx ;Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"");
                theConnection.Open();
                OleDbDataAdapter theDataAdapter = new OleDbDataAdapter("SELECT * FROM [Working$]", theConnection);
                DataSet theDS = new DataSet();
                DataTable dt = new DataTable();
                theDataAdapter.Fill(dt);
                this.dataGridView1.DataSource = dt.DefaultView;
                theConnection.Close();
            }
            catch (Exception ex)
            { 

            }

        }

        private void BindGridForSql()
        {
            string connectionString = "Data Source=192.168.0.11;Initial Catalog=30_Nov_13;User ID=sa;Password=super";
            string sql = "SELECT * from [@BA_ODPV] ";

            using (var connection = new SqlConnection(connectionString))
            using (var command = new SqlCommand(sql, connection))
            using (var adapter = new SqlDataAdapter(command))
            {
                connection.Open();
                var dataEntry1 = new DataTable();
                adapter.Fill(dataEntry1);
                dataGridView2.DataSource = dataEntry1;
            }

        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection rc = null;
            rc = dataGridView1.SelectedRows;
            sno = rc[0].Cells["F1"].Value.ToString();

NOW HERE I WANT TO SEARCH THE SELECTED DATA IN SNO "sno = rc[0].Cells["F1"].Value.ToString();" IN THE BindGridForSql() GRIDVIEW.. 
THE SNO IS THE BindGridForExcel() GRIDVIEW.. PLZ 
        }
Posted
Updated 22-Nov-13 17:48pm
v2
Comments
[no name] 22-Nov-13 10:15am    
you might want to look at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.filterexpression(v=vs.110).aspx
Jawad Ahmed Tanoli 22-Nov-13 11:16am    
if the datasource is a datatable you can search in that like dt.select("sno='1'") if record exsist then select grid row or clear previous data in grid and assign new datatasource from exsistg datatable..may be helpful
Maciej Los 22-Nov-13 11:35am    
And the question is....
[no name] 22-Nov-13 15:35pm    
as far as I can understand,op want master-detail functionality...based on the click on the first grid...he want to do search in the second grid...
Karthik_Mahalingam 22-Nov-13 11:40am    
pls make your question clear..

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