使用ASP.NET(C#)在ACCESS DB中输入日期/时间

时间:2013-01-10 14:49:19

标签: asp.net ms-access-2007

我想在我的ACCESS数据库中输入DATE,该字段为DATE / TIME。 用户以此方法(文本)DD / MM / YYYY

的形式输入

代码: 日期/时间对象

DateTime Bday = new DateTime(long.Parse(Request.Form["Bday"]));

SQL QUERY:

cmd.CommandText = "INSERT INTO (Fname,Lname,User,Pass,Email,BiDate,IsAdmin,IsMale) VALUES ('" + fname + "','" + lname + "','" + user + "','" + pass + "','" + email + "',#" + Bday + "#," + admin + "," + male + ")";

无效

1 个答案:

答案 0 :(得分:0)

删除long.Parse部分

        DateTime Bday = DateTime.ParseExact(Request.Form["Bday"], "dd/MM/yyyy", 
        CultureInfo.InvariantCulture);

        cmd.CommandText = "INSERT INTO (Fname,Lname,[User],Pass,Email,BiDate,"
        +"IsAdmin,IsMale) " + 
        "VALUES ('" + fname + "','" + lname + "','" + user + "','" + pass + "','"
        + email + "',#" + Bday.ToString("dd/MM/yyyy") + "#," + admin + "," + male + ")";

希望这有帮助!