qq_31341445 2017-06-19 03:02 采纳率: 100%
浏览 1131
已采纳

求助大神vs窗体该怎么求sqlserver里两个时间相减的差。借阅系统。代码如下

private void button1_Click(object sender, EventArgs e)
{

        SqlConnection conn = new SqlConnection("Data Source=LAPTOP-C0MIMKL4\\SQLEXPRESSS;Initial Catalog=借阅系统;Integrated Security=True");
        conn.Open();
        string sql = "update book set benshu=benshu+'" + textBox3.Text + "' where bnum = '" + textBox1.Text.Trim() + "'";
        string jtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        string sql1 = "insert into borrow values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + "归还" + "','" + jtime + "')";
        string sqllr = sql + sql1;
        SqlCommand cmd = new SqlCommand(sqllr, conn);
        int count = cmd.ExecuteNonQuery();
        conn.Close();
        if (count > 0)
        {
            DateTime t1 = DateTime.Parse(jtime);
            string str1 = "select time from borrow where bnum ='" + textBox1.Text.Trim()+"'";
            DateTime t2 = Convert.ToDateTime(str1);
            TimeSpan t3 = t1 - t2;
            double getDay = t3.TotalDays;
            double a = getDay - 30;
            if (a > 0)
            {
                MessageBox.Show("归还成功!您已超期");
                MessageBox.Show("您已超期" + a + "天\n罚金为" + a + "* 1元");
            }
            else
                MessageBox.Show("归还成功");
        }
        textBox4.Text = jtime;

    }
  • 写回答

3条回答 默认 最新

  • BloodyMandoo 2017-06-19 03:09
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏