我目前遇到的问题是日期是以30/12/1899输入SQL数据库的。我正在使用Access 2003进行数据库,并且无法想到发生这种情况的任何可能原因!
window.status='Loading contingency scripts - please wait...';
audit('Loading contingency scripts');
var conting={ i:0
,start:function(){
window.status='Loading form - please wait...';
var t='';
t+='<form name="frm_conting" id="frm_conting" onsubmit="return false;">';
t+='<table width="100%" cellspacing="1" cellpadding="0">';
t+='<tr><td>Date (DD/MM/YY):</td><td><input type="text" size="8" value="'+current_date+'" id="date"></td></tr>';
t+='<tr><td>Time Started:</td><td><select id="timefrom"><option></option>';
for(h=8;h<23;h++){
for(m=0;m<46;m=m+15){ t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>'; };
};
t+='</select></td></tr>';
t+='<tr><td>Time Finished:</td><td><select id="timeto"><option></option>';
for(h=8;h<23;h++){
for(m=0;m<46;m=m+15){ t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>'; };
};
t+='</select><tr><td>Extension #:</td><td><input type="text" size="5" value="'+my.extension+'" id="staffid"></td></tr>';
t+='<tr><td>Desk ID:</td><td><input type="text" size="5" value='+my.deskid+' id="desk"></td></tr>';
t+='<tr><td>Number of calls:</td><td><input type="text" size="5" id="calls"></td></tr>';
t+='<tr><td>Avid ID:</td><td><input type="text" size="5" id="avid"></td></tr>';
t+='<tr><td><input type="button" value="Submit" onClick="conting.save()"></td>';
t+='</table>';
t+='</form>';
div_form.innerHTML=t;
window.resizeTo(400,385);
window.status='';
}
,save:function(){
var conting_date=frm_conting.date.value;
if(!isdate(conting_date)){alert("You have entered an incorrect date.");return false;};
var conting_timefrom=frm_conting.timefrom.value;
var conting_timeto=frm_conting.timeto.value;
if(conting_timefrom==''||conting_timeto==''){alert("You need to enter a starting & finishing time.");return false;};
if(conting_timefrom>conting_timeto){alert("The time you have entered is after the finish time.");return false;};
var conting_staffid=frm_conting.staffid.value;
if(conting_staffid.length!=5) { alert("You have entered an incorrect extension number.");return false;};
var conting_desk=frm_conting.desk.value;
if(conting_desk.length!=5) { alert("You have entered an incorrect desk ID.");return false;};
var conting_calls=frm_conting.calls.value;
if(isNaN(conting_calls)){alert("You have not entered amount of calls.");return false;};
var conting_avid=frm_conting.avid.value;
if(isNaN(conting_avid)){alert("You have entered an incorrect avid ID.");return false;};
if(conting_avid.length!=5) { alert("You have entered an incorrect avid ID.");return false;};
conn.open(db["contingency"]);
rs.open("SELECT MAX(prac_id) FROM practice",conn);
var prac_id=rs.fields(0).value+1;
var prac_staffid=frm_conting.staffid.value;
var prac_date=frm_conting.date.value;
var prac_timefrom=frm_conting.timefrom.value;
var prac_timeto=frm_conting.timeto.value;
var prac_calls=frm_conting.calls.value;
var prac_avid=frm_conting.avid.value;
rs.close();
var q="INSERT INTO practice (prac_id, prac_staffid, prac_date, prac_timefrom, prac_timeto, prac_extension, prac_desk, prac_calls, prac_avid) VALUES ("+prac_id+","+my.id+", "+prac_date+", '"+prac_timefrom+"', '"+prac_timeto+"', '"+my.extension+"', '"+my.deskid+"', '"+prac_calls+"', '"+prac_avid+"')";
rs.open(q,conn);
conn.close();
alert("Your contingency times were successfully added.");
window.status='';
conting.start();
}
};
window.status='';
答案 0 :(得分:1)
30/12/1899是Access数据库的“零”日期。
prac_date变量很可能不包含正确的日期时间值。它缺失,不完整或畸形。在执行查询之前提醒或记录它,以查看进入查询的实际值并验证它是否正确。
您可能想看看MSDN forum中讨论的类似主题。
答案 1 :(得分:1)
我能想到的是 - 输入的文本为空/未正确检索,因此被同化为0,这是javascript或数据库的T0时间 - 输入的文本是31/12/99,但是这个年份为2位的格式在数据库中映射到1899。如果是这种情况,您应该在插入查询中明确设置日期格式。