为什么valuechanged事件没有触发?

excallibur excallibur 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下
private void 转到日期GToolStripMenuItem_Click(object sender, EventArgs e)
{
dtp转到日期.Visible = true;

}

private void dtp转到日期_ValueChanged(object sender, EventArgs e)
{
dtp日期.Value = dtp转到日期.Value;
dtp转到日期.Visible = false;
}
private void dtp日期_ValueChanged(object sender, EventArgs e)
{

dairyLoad();

}
public void dairyLoad()
{
DateTime dtp= dtp日期.Value;
string rtb = rtb内容.Text, tb = tb标题.Text;
SqlCommand thisCommand = Pub.CC.Conn.CreateCommand();
thisCommand.Parameters.Add("@a1", dtp);
thisCommand.CommandText = "select dairytent from dairy1 where dairytime=@a1";

object countResult = thisCommand.ExecuteScalar();
if (countResult != null)
{
countResult = thisCommand.ExecuteScalar();
string neirong = countResult.ToString();
rtb内容.Text = neirong;
thisCommand.Parameters.Add("@a2", dtp);
thisCommand.CommandText = "select dairyname from dairy1 where dairytime=@a2";
object countResult2 = thisCommand.ExecuteScalar();
string biaoti = countResult2.ToString();
tb标题.Text = biaoti;
}
else if(countResult==null)
{
rtb = "";
tb = "";
SqlParameter[] pas = new SqlParameter[] {new SqlParameter("@b1", rtb), new SqlParameter("@b2", tb), new SqlParameter("@b3", dtp) };

Pub.CC.ExecuteSql("insert into dairy1 (dairytent,dairyname,dairytime) values (@b1,@b2,@b3)",pas);
rtb内容.Text = "";
tb标题.Text="";
}
}
调试的时候一旦执行 dtp转到日期_ValueChanged 而改变dtp日期的值后, if (countResult != null) 里面的代码就不执行了,数据库中的值就掉不出来,而直接手动改变dtp日期的值则不受影响。注:数据库里绝对有值!
...全文
评论 4
收藏 已收藏
分享
返回顶部
excallibur
C# 111,129 成员 642,540 内容