我是 C# 的新手..
我有写功能来过滤部门。这个函数将返回idDepartment。
新问题是,部门保持价值“ System.Windows.Forms.Label,Text:ADMIN ”,这就是我得到零的原因。那么我怎样才能只接受“ADMIN”并留在部门?
更新 :
public partial class frmEditStaff : Form
{
private string connString;
private string userId, department; //Department parameter coming from here
private string conString = "Datasource";
public frmEditStaff(string strUserID, string strPosition)
{
InitializeComponent();
//Pass value from frmListStaff to userID text box
tbStaffId.Text = strUserID.ToString();
userId = strUserID.ToString();
department = strPosition.ToString();
}
下面的代码正在运行,没有任何问题。
public int lookUpDepart()
{
int idDepart=0;
using (SqlConnection openCon = new SqlConnection(conString))
{
string lookUpDepartmenId = "SELECT idDepartment FROM tbl_department WHERE department = '" + department + "';";
openCon.Open();
using (SqlCommand querylookUpDepartmenId = new SqlCommand(lookUpDepartmenId, openCon))
{
SqlDataReader read = querylookUpDepartmenId.ExecuteReader();
while (read.Read())
{
idDepart = int.Parse(read[0].ToString());
break;
}
}
openCon.Close();
return idDepart;
}
}
感谢帮助。快乐美好的一天!