Uploadaspx:
<%@ LANGUAGE=JAVASCRIPT %>
<! #include file = "/adojvsinc">
<! #include file = "/conninc">
<%
// 執行SQL語句
// Gu Laicheng
function RunSQL(MySQL)
{
var ret="";
var rs = ServerCreateObject("ADODBRecordset");
rsCursorType = adOpenKeyset;
rsLockType = adLockBatchOptimistic;
// ResponseWrite("<br/>" + MySQL + "");
try {
rsOpen(MySQLconn);
}
catch (ex) {
var ErrStrErrStrErrStr="==>"+new Date()+"<br/>";
ErrStr = "Error:"+ex+"<br/>"+MySQL;
var o = connErrors;
for (var i=;i<oCount;i++)
{
ErrStr += oItem(i)Number + ":" + oItem(i)Description+" "+oItem(i)SQLState+";"+oItem(i)Source ;
}
ErrStr =ErrStr+"<br/>"+ErrStr;
oClear();
ResponseWrite("<br/>" + ErrStr + "");
}
if(rsState==)
{
if (!(rsBOF && rsEOF))
{
ret = rs()value;
}
rsClose();
}
return ret;
}
var Class = {
create: function() {
return function(n) {
thisinitializeapply(this arguments);
}
}
}
var TABLE = Classcreate();
TABLEprototype = {
initialize:function(TabName){
thisTabName = TabName;
thisFields=[];
thisFieldCount = ;
thisvalues=[];
thistypes=[];
thisMySQL="";
thisflag;
}
F:function(s)
{
var a=ssplit("");
for(var i=;i<alength;i++)
{
thisFields[i]=a[i];
}
thisFieldCount = alength;
}
V:function(s)
{
var a=ssplit("");
thisflag=a[];
for(var i=;i<alength;i++)
{
thisvalues[i]=a[i];
}
if(a[]==) thisReplace();
if(a[]==) thisInsert();
if(a[]==) thisUpdate();
if(a[]==) thisDelete();
}
Replace:function()
{
if(thisvalues[]==)
thisInsert();
else
thisUpdate();
}
Insert:function()
{
var fs=""vs="";
var j=; //ij可能並不同步有些列值可能為空表示不插入其值要保證sql的語法正確
for(var i=;i<thisFieldCount;i++)
{
if(thisvalues[i] == "NULL") continue;
if(j == )
{
fs += thisFields[i];
vs += ""+thisvalues[i]+"";
} else
{
fs += ""+thisFields[i];
vs += ""+thisvalues[i]+"";
}
j++;
}
thisMySQL="insert into "+thisTabName+" ("+fs+") values ("+vs+")";
}
Update:function()
{
thisMySQL="update "+thisTabName+" set ";
for(var i=;i<thisFieldCount;i++)
{
if(thisvalues[i] == "NULL")
{
if(i != ) thisMySQL += "";
thisMySQL += thisFields[i]+"=null ";
} else
{
if(i != ) thisMySQL += "";
thisMySQL += thisFields[i]+"="+thisvalues[i]+"";
}
}
thisMySQL += " where "+thisFields[]+"="+thisvalues[]+"";
}
Delete:function()
{
thisMySQL="delete from "+thisTabName+" where ";
var j=; //ij可能並不同步有些列值可能為空表示不以其為條件要保證sql的語法正確
for(var i=;i<thisFieldCount;i++)
{
if(thisvalues[i]=="") continue;
if(thisvalues[i] == "NULL")
{
if(j != ) thisMySQL += " and ";
thisMySQL += thisFields[i]+" is null ";
} else
{
if(j != ) thisMySQL += " and ";
thisMySQL += thisFields[i]+"="+thisvalues[i]+"";
}
j++;
}
}
};
var fso ts s;
var ForReading = ForWriting = ;
var name;// = "c:webyafulwisadttcsv";
name = ServerMapPath("tcsv");
var fso = new ActiveXObject("ScriptingFileSystemObject");
if (fsoFileExists(name))
{
ResponseWrite(" 文件 "+name+" 存在!");
ts = fsoOpenTextFile(name ForReading true);
// tsSkipLine();
var data=new TABLE(RequestQueryString("a")+"");
s = tsReadLine();
dataF(s);
ResponseWrite("<br/>"+dataFieldCount);
ResponseWrite("<br/>" + sreplace(//g"t") + "");
ResponseWrite("<br/>" + dataFields + "");
while (!tsAtEndOfStream)
{
s = tsReadLine();
// ResponseWrite("<br/>" + sreplace(//g"t") + "");
dataV(s);
ResponseWrite("<br/>" + dataMySQL + "");
RunSQL(dataMySQL);
}
tsClose();
}
else
{
ResponseWrite(" 文件 "+name+" 不存在請核對後查詢!");
}
%>
From:http://tw.wingwit.com/Article/program/net/201311/14339.html