OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
cmd = new OleDbCommand(sqlQuery, conn);
cmd.CommandText = "INSERT INTO tickets (ProblemIncidentDate, ProblemIncidentTime, user, StateTagNumber, ProblemType, ProblemDescription, ProblemStatus) VALUES (@ProblemDate,@ProblemTime,@userIDNumber,@StateTag,@ProblemType,@ProblemDescription,@ProblemStatus)";
cmd.Parameters.Add("@ProblemDate", OleDbType.Date).Value = labelProblemDate.Text.Trim();
cmd.Parameters.Add("@ProblemTime", OleDbType.DBTimeStamp).Value = labelProblemTime.Text.Trim();
cmd.Parameters.Add("@userIDNumber", OleDbType.Integer).Value = Convert.ToInt32(userID.ToString());
cmd.Parameters.Add("@StateTag", OleDbType.VarChar).Value = textBoxStateTagNumber.Text.Trim();
cmd.Parameters.Add("@ProblemType", OleDbType.VarChar).Value = comboBoxProblemType.SelectedItem.ToString();
cmd.Parameters.Add("@ProblemDescription", OleDbType.VarChar).Value = textBoxProblemDescription.Text.Trim();
cmd.Parameters.Add("@ProblemStatus", OleDbType.VarChar).Value = "Open";
cmd.ExecuteNonQuery(); //At this line exception is generating
conn.Close();
我的數據庫是一個Microsoft Access 2007我一直使用的OleDbConnection和OleDbCommand的
這裏插入一條記錄崩潰的字段類型
ID AutoNumber
ProblemIncidentDate Date/Time
ProblemIncidentTime Date/Time
user Number
StateTagNumber Text
ProblemType Text
ProblemDescription Memo
ProblemResolution Memo
ProblemStatus Text
我想不通爲什麼它崩潰
控制檯消息說
類型'系統的第一次機會例外.Data.OleDb.OleDbException」出現在system.data.dll
您得到的錯誤是什麼? – Iridio 2012-04-26 16:17:05
它可以幫助您發佈錯誤。通常,錯誤消息包含有關問題的提示。 – tsells 2012-04-26 16:18:10
試着圍繞'[user]'放置括號,它可能是關鍵字。此外,您正在將字符串傳入Integer和DateTime字段。 – LarsTech 2012-04-26 16:18:54