这是代码的一部分..
//这里是插入
OleDbCommand command = new OleDbCommand();
command.CommandText = "INSERT INTO tblUsersAccount (Username,[Password],Firstname, MiddleName, Lastname,Birthday,ContactNo,DateCreated,DateModified) values (@Username,@Password,@Firstname,@MiddleName,@Lastname,@Birthday,@ContactNo,@DateCreated,@DateModified)";
command.Parameters.Add("@Username", OleDbType.Char).Value = tbUsername.Text;
command.Parameters.Add("@Password", OleDbType.Char).Value = tbPassword.Text;
command.Parameters.Add("@Firstname", OleDbType.Char).Value = tbFirstname.Text;
command.Parameters.Add("@MiddleName", OleDbType.Char).Value = tbMiddleName.Text;
command.Parameters.Add("@Lastname", OleDbType.Char).Value = tbLastname.Text;
command.Parameters.Add("@Birthday", OleDbType.Date).Value =DateTime.Parse(tbBirthday.Text);
command.Parameters.Add("@ContactNo", OleDbType.Char).Value = tbContactNo.Text;
command.Parameters.Add("@DateCreated", OleDbType.Date).Value = DateTime.Now;
command.Parameters.Add("@DateModified", OleDbType.Date).Value = DateTime.Now;
command.ExecuteNonQuery();
//这里是更新
OleDbCommand command = new OleDbCommand();
command.CommandText = "UPDATE tblUsersAccount SET Password = ?, Firstname = ?, MiddleName = ?, Lastname = ?, Birthday = ?, ContactNo = ? WHERE Username = ?";
connect.ConnectionString = connectionString;
connect.Open();
command.Connection = connect;
command.Parameters.Add("@Username", OleDbType.Char).Value = tbUsername.Text;
command.Parameters.Add("@Password", OleDbType.Char).Value = tbPassword.Text;
command.Parameters.Add("@Firstname", OleDbType.Char).Value = tbFirstname.Text;
command.Parameters.Add("@MiddleName", OleDbType.Char).Value = tbMiddleName.Text;
command.Parameters.Add("@Lastname", OleDbType.Char).Value = tbLastname.Text;
command.Parameters.Add("@Birthday", OleDbType.Date).Value =DateTime.Parse(tbBirthday.Text);
command.Parameters.Add("@ContactNo", OleDbType.Char).Value = tbContactNo.Text;
command.ExecuteNonQuery();
问题#1:更新部分出错。错误说,“该字符串未被识别为有效的日期时间。从索引 0 开始有一个未知单词。” 这是生日部分。即使日期格式正确,例如 09/08/11。它适用于插入部分。
问题 #2:当我尝试删除生日部分以查看除了问题 #1 之外是否还有其他错误时,出现错误“更新语句中的语法错误”。
对不起..我只是编程新手。并感谢您的帮助。上帝保佑。