从SQL表中提取数据后标签不会更改

时间:2013-12-30 19:39:27

标签: c# sql winforms forms

Form

亲爱的用户之后的用户标签将通过lblcName.Text = detail;

中的代码相应地更改为当前登录的用户

我根据登录的用户创建了iCount,Viewer和Time更改的代码,获取用户数据并在此处显示。但是标签没有改变..在这段代码中我可能做错了什么?

breakpoint放在DataRow firstRow = dtC.Rows[0];上进行调试显示我的label iCount值为1,但未更改值,viewertime label值也是查看者和时间

public partial class Notification : Form
    {
        public Notification(string detail)
        {
            InitializeComponent();
            lblcName.Text = detail;
        }

        private void Notification_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=PEWPEWDIEPIE\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
            conn.Open();
            DataTable dtC = new DataTable();

            SqlDataAdapter daCount = new SqlDataAdapter("select iCount,LastView,Viewtime from ComDet where cName = @cName", conn);
            daCount.SelectCommand.Parameters.Add("@cName", SqlDbType.VarChar).Value = lblcName.Text;

            daCount.Fill(dtC);
            DataRow firstRow = dtC.Rows[0];

            lblCount.Text = firstRow["iCount"].ToString();
            lblLastView.Text = firstRow["LastView"].ToString();
            lblView.Text = firstRow["ViewTime"].ToString();
conn.Close();


        }
    }

1 个答案:

答案 0 :(得分:0)

首先,确保数据库不为空。其次,使用刷新表单控件的表单的Validate()方法。