通过使用搜索btn以表单显示数据库记录 [英] Displaying database Records in a form by using Search btn

查看:55
本文介绍了通过使用搜索btn以表单显示数据库记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi 4nds

我创建了一个带有某些控件的表单,并将其与数据库连接.然后,我想以另一种形式通过搜索按钮提供参数来显示特定的员工记录.

请帮我找出来.

hi 4nds,

I created a form with some controls and connected it with database. Then, in another form i would like to display the particular employee records by giving a parameter through search button.

please help me to find it out.

推荐答案



1)首先获取该特定员工的employeeId
然后写一个查询,

2)连接到数据库
3)将结果放入数据集
4)提供所需的任何详细信息作为gridview的数据源

谢谢


1) first of all get the employeeId of that perticular employee
then write a query according that,

2) connect to the database
3) get the results into dataset
4) provide a dataset as a datasource to gridview with whatever the details you want

Thanks


如果您使用datagridview显示员工详细信息会更好

使用onbuttonclick
It can be better if you use datagridview to show employee details

use onbuttonclick
private void button3_Click(object sender, EventArgs e)
       {
           try
           {
               string strdate = "select *from emp where emp name like '%'+@name+'%'";
               SqlCommand cmddate = new SqlCommand(strdate, Db.GetConnection());
               cmddate.Parameters.AddWithValue("name",textbox1.Text);

               SqlDataAdapter dadate = new SqlDataAdapter(cmddate);
               DataTable dtdate = new DataTable();
               dadate.Fill(dtdate);
               dataGridView1.DataSource = dtdate;
               dataGridView1.Refresh();
           }
           catch (Exception ex)
           {
           }
       }


这篇关于通过使用搜索btn以表单显示数据库记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆