本文介绍了Windows应用程序-按下搜索按钮时未将其特定行检索到datagridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Sirs/Madames

我正在Visual Studio中的Windows应用程序中尝试.在这里,在新表单中,我在其前面创建了三个标签tomarw [?] ,三个标签和一个搜索"按钮.

在下面,我创建了DataGridView,因为我使用了数据源,因此我已经连接了这三个名称的表,并且还编写了一个查询以查询要连接的那三个名称.在此之后的问题是,它正在给填充"之类的东西,并且搜索按钮"将可见,但不执行任何操作,我必须单击填充本身...

因此,当我输入名称并单击搜索按钮时,将显示其行,但没有发生.输入并单击搜索按钮"后,它不会检索其特定行.


谢谢
Pradeeep CBZ

Hello Sirs/Madames

I''m trying in windows application in visual studio. Here in a new Form, I had created three lables tomarw [?] in front of it three TextBoxes and one "search": button.

Below to that I had created DataGridView in that I used data source by that I had connected the table of those three names and also I had wrote a query for those to connect. Here after that the problem is, it is giving "fill" something like that and the "Search button" will be visible but not performing any action, I have to click a fill itself...

So when I enter the names and click the search button, its row will be displayed, but it is not happening. It is not retriving its particular row when after entering and hitting the "Search button".


Thanks
Pradeeep CBZ

推荐答案

private void button3_Click(object sender, EventArgs e)
       {
           try
           {
               string strdate = null;
               if (rights == "Admin")
               {
                   strdate = "select tblassignAsset.productId,tblassignAsset.tagno as Tag_No,tblassignAsset.remarks as Remarks,tblassignAsset.assigndate as Assigned_Date,empbirth.userid as Emp_Code,empbirth.name as Name,empbirth.Deptt,empbirth.Designation,tblAsset.type as Type,tblAsset.brand as Brand,tblAsset.description as Description,tblAsset.specifications as Specifications  from ((tblassignAsset INNER JOIN empbirth ON empbirth.userid=tblassignAsset.empcode) INNER JOIN tblAsset ON tblAsset.productId=tblassignAsset.productId) where ((empbirth.name like '%'+@value+'%') or empbirth.Deptt like '%'+@value+'%' or tblAsset.type like '%'+@value+'%' or tblAsset.description like '%'+@value+'%' or tblAsset.Status like '%'+@value+'%') and tblassignAsset.recieveddate is NULL";
               }
               else
               {
                   strdate = "select tblassignAsset.productId,tblassignAsset.tagno as Tag_No,tblassignAsset.remarks as Remarks,tblassignAsset.assigndate as Assigned_Date,empbirth.userid as Emp_Code,empbirth.name as Name,empbirth.Deptt,empbirth.Designation,tblAsset.type as Type,tblAsset.brand as Brand,tblAsset.description as Description,tblAsset.specifications as Specifications from ((tblassignAsset INNER JOIN empbirth ON empbirth.userid=tblassignAsset.empcode) INNER JOIN tblAsset ON tblAsset.productId=tblassignAsset.productId) where ((empbirth.name like '%'+@value+'%' or empbirth.Deptt like '%'+@value+'%'  or tblAsset.description like '%'+@value+'%' or tblAsset.Status like '%'+@value+'%') and tblAsset.type like '%" + rights + "%') and tblassignAsset.recieveddate is NULL";

               }
               SqlCommand cmddate = new SqlCommand(strdate, Db.GetConnection());
               cmddate.Parameters.AddWithValue("value",textBox1.Text);
               SqlDataAdapter dadate = new SqlDataAdapter(cmddate);
               DataTable dtdate = new DataTable();
               dadate.Fill(dtdate);
               dataGridView1.DataSource = dtdate;
               dataGridView1.Refresh();
           }
           catch (Exception ex)
           {
           }
       }





如果您要将datagridview与数据集绑定,则
您的数据集查询应具有您要与textbox1映射的参数,例如



or

if you are binding datagridview with dataset then
your dataset query should have parameter that you map with textbox1 like

this.yourTableAdapter.Fill(this.yourdataset.tablename, textbox1.Text);


这篇关于Windows应用程序-按下搜索按钮时未将其特定行检索到datagridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:18