本文介绍了如何在数据GridView中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 hi guyz, i有两个数据网格视图命名excelGV和sqlGV都在同一表格上可见。 一个已连接来自excel,另一个是来自sql server .. excelGV中有3列sno,name和fone no。 双倍在excelGV上单击事件,它会保存所选行的sno。 现在我希望在sqlGV中对sno搜索数据.. 谢谢.. 更新.. 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..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 } 推荐答案 这篇关于如何在数据GridView中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 10:28