Take value from query to label in C#

前端 未结 8 1122
逝去的感伤
逝去的感伤 2021-01-26 12:48

How can i take value from query result to label?

I have two label, one is labelName and one more is labelDepartment

So when i r

8条回答
  •  一向
    一向 (楼主)
    2021-01-26 13:36

    //Open SQL connection
    
    SqlConnection openCon = new SqlConnection(connString);
    openCon.Open();
    
    string SQL = string.Format("SELECT tbl_staff.staffName,tbl_department.department FROM tbl_staff,tbl_logs,tbl_department WHERE tbl_staff.userID = tbl_logs.userID and tbl_staff.idDepartment = tbl_department.idDepartment" + listStaff.SelectedValue + ";");
    
    
    SqlCommand command = new SqlCommand(SQL);
    SqlDataReader reader = command.ExecuteReader();
    
    while(reader.Read())
    {
        labelName.Text = reader["tbl_staff.staffName"].ToString();
        labelDepartment.Text = reader["tbl_department.department"].ToString();
    }
    

    Convert Type is what you left in your code....

提交回复
热议问题