首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

该字符串未被辨别为有效的 DateTime

2013-07-20 
该字符串未被识别为有效的 DateTime。 String conn @Data Sourcepo-pcInitial CatalogaspnetdbUser

该字符串未被识别为有效的 DateTime。
 String conn = @"Data Source=po-pc;Initial Catalog=aspnetdb;User ID=sa;Password=123";
            SqlConnection connstring = new SqlConnection(conn);
            connstring.Open();
            
            string st1 ="+DropDownList1.Text+";
            string st2 ="+ DropDownList2.Text+";[b]
[/b]
            string st3="SELECT * T1 FROM book where booktime="+DropDownList3.Text+"";
            DateTime dt1 = Convert.ToDateTime(st1);
            DateTime dt2 = Convert.ToDateTime(st2);
            DateTime dt3 = Convert.ToDateTime(st3);
            if (DateTime.Compare(dt1, dt2) < 0)
            {
                cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
                cn.Open();

                SqlCommand cmd = new SqlCommand("UPDATE book SET T1= '" + DropDownList3.Text + "'+'" + DropDownList1.Text + "'+'" + DropDownList2.Text + "'+ '" + TextBox4.Text.Replace("'", "''") + "'  where booktime= '" + TextBox1.Text.Replace("'", "''") + "'", cn);
                 cmd.ExecuteNonQuery();
                 cn.Close();
该字符串未被辨别为有效的 DateTime这是DropDownList1里的值


[解决办法]
string st1 = DropDownList2.Text;
        Response.Write(Convert.ToDateTime(st1).ToString());

没有问题
[解决办法]
 这样
string st3 = "SELECT *  FROM book where booktime=" +TextBox1.Text + "";
            SqlCommand cmd1 = new SqlCommand(st3,conn);
           SqlDataReader dr = cmd1.ExecuteReader();
            if (dr.Read())
            {
                this.Label14.Text = dr[0].ToString();
            }

            string st4 = Label14.Text.Trim();
            Response.Write(Convert.ToDateTime(st4).ToString());

热点排行