Value is zero after filter SQL in C#
Posted
by
Chuki2
on Stack Overflow
See other posts from Stack Overflow
or by Chuki2
Published on 2012-09-04T08:42:38Z
Indexed on
2012/09/04
15:39 UTC
Read the original article
Hit count: 142
I`m new in C#..
I have write function to filter department. And this function will return idDepartment.
New problem is, department keep value "System.Windows.Forms.Label, Text : ADMIN ", that`s why i got zero. So how can i take "ADMIN" only and keep to department?
Update :
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();
}
This code below is working, don`t have any problem.
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;
}
}
Thanks for help. Happy nice day!
© Stack Overflow or respective owner