如何显示发送消息的日期... [英] how to display date on which message is send...

查看:118
本文介绍了如何显示发送消息的日期...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

废料

ID
ToId
FromId
SendDate


Scrap

Id
ToId
FromId
SendDate


protected void ButtonPostScrap_Click(object sender, EventArgs e)
    {
        if (!object.Equals(Session["Id"], null))
        {


            string postScrap = "Insert INTO Scrap (FromId,ToId,Message) VALUES('" + Session["Id"].ToString() + "','" + Request.QueryString["Id"].ToString() + "','" + TextBoxScrap.Text + "')";
            dbClass.ConnectDataBaseToInsert(postScrap);
           Response.Redirect("UserDetails.aspx?Id=" + Request.QueryString["Id"].ToString());
        }

推荐答案

如果您正在显示数据库中的消息,那么唯一可以确定发送时间的方法就是是否将该日期存储在数据库.设置一个DateTime类型的字段,并将其设置为DateTime.Now.

顺便说一句:不要像这样对您的数据库进行访问,连接字符串是一个非常糟糕的主意:它使您容易受到意外或蓄意的SQL Injection攻击的攻击,该攻击可能会删除整个数据库.请改用参数化查询.请稍等一下,如果我发布一条消息会发生什么情况:
If you are displaying messages from your database, then the only way you can tell when it was sent, is if you store that date in the database. Set up a field, of DateTime type, and set it to DateTime.Now.

BTW: don''t do your database acceess like that, concatenating strings is a very bad idea: it leaves you wide open to an accidental or deliberate SQL Injection attack which could delete your entire database. Use Parametrized queries instead. Just consider for a moment what would happen if I posted a message:
Hello'');DROP TABLES;--

建议您尝试一下,而无需先备份数据库...

I do not recommend you try it, without backing your database up first...


这篇关于如何显示发送消息的日期...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆