代码如下
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日期的值则不受影响。注:数据库里绝对有值!
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日期的值则不受影响。注:数据库里绝对有值!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货