日期:2014-05-17  浏览次数:20935 次

C#与SQL2008的问题
 private void dtp日期_ValueChanged(object sender, EventArgs e)
        {

            dairyLoad();

        }
这段代码能正常执行,这个时间触发后能正常返回值

 public void dairyLoad()
        {
            Pub.CC.ExecuteSql("delete dairy1 from dairy1 where dairyname=''");
            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;
            }