strSQL = "insert into regist(userID,passwd,regDate) values('"+txtUserID.Text+"','"+txtPasswd.Text+"',"+DateTime.Parse(DateTime.Now.ToString())+")";改成strSQL = "insert into regist(userID,passwd,regDate) values('"+txtUserID.Text+"','"+txtPasswd.Text+"', '"+DateTime.Parse(DateTime.Now.ToString())+"')";
时间型字段添加时需要加单引号。
时间型字段添加时需要加单引号。
不是字符才加吗?To: brightheroes(老五)
取当前系统时间的意思。
strSQL = "insert into regist(userID,passwd,regDate) values(@userID,@passwd,@regDate)";
SqlCommand myComm = new SqlCommand(strSQL,myConn);
myComm.Parameters.Add("@userID",txtUserID.Text);
myComm.Parameters.Add("@passwd",txtPasswd.Text);
myComm.Parameters.Add("@regDate",DateTime.Now);
这样可以避免很多麻烦。