本文介绍了我想通过Empid在员工数据库上搜索,所以我在表单上创建了这段代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void btnSearch_Click(object sender, EventArgs e)
{
if (searchtext.Text == "")
{
MessageBox.Show("Plese Inter Employee's ID you are searching for");
searchtext.Focus();
}
else
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Employees.mdb");
OleDbDataAdapter ad = new OleDbDataAdapter("select * from Employee where EmpID=@EmpID", con);
ad.SelectCommand.Parameters.Add("@EmpID", OleDbType.Integer);
ad.SelectCommand.Parameters["@EmpID"].Value = int.Parse(searchtext.Text);
DataSet ds = new DataSet();
ad.Fill(ds, "Emp");
DGV1.DataSource = ds.Tables["Emp"];
if (ds == null)
{
MessageBox.Show("not found!!");
}
else
{
MessageBox.Show("The Employee you are searching for is listed down, if you want to update the data click the arrow sign on the lift side of the record");
}
}
}
}
推荐答案
OleDbDataAdapter ad = new OleDbDataAdapter("select * from Employee where EmpID=@AutherID", con);
ad.SelectCommand.Parameters.Add("@EmpID", OleDbType.Integer);
ad.SelectCommand.Parameters["@EmpID"].Value = int.Parse(searchtext.Text);
@AutherId
并且仅提供 @EmpID
?
也许你的意思是:
Checking against @AutherId
and only providing @EmpID
?
Perhaps you meant:
OleDbDataAdapter ad = new OleDbDataAdapter("select * from Employee where EmpID=@EmpID", con);
ad.SelectCommand.Parameters.Add("@EmpID", OleDbType.Integer);
ad.SelectCommand.Parameters["@EmpID"].Value = int.Parse(searchtext.Text);
这篇关于我想通过Empid在员工数据库上搜索,所以我在表单上创建了这段代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!