亲爱的用户之后的用户标签将通过lblcName.Text = detail;
我根据登录的用户创建了iCount,Viewer和Time更改的代码,获取用户数据并在此处显示。但是标签没有改变..在这段代码中我可能做错了什么?
将breakpoint
放在DataRow firstRow = dtC.Rows[0];
上进行调试显示我的label
iCount
值为1,但未更改值,viewer
和time
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();
}
}
答案 0 :(得分:0)
首先,确保数据库不为空。其次,使用刷新表单控件的表单的Validate()方法。