Upload.aspx:
<%@ language= ' JAVASCRIPT '%>
<!--#include file = ". /adojvs.inc "-->
<!--#include file = ". /conn.inc "-->
<%
Execute SQL statement
2012-12-6 Gu Laicheng
function RunSQL (MySQL)
{
var ret= "";
var rs1 = Server.CreateObject ("ADODB.") Recordset ");
Rs1. CursorType = adOpenKeyset;
Rs1. LockType = adLockBatchOptimistic;
Response.Write ("<br/>" + MySQL + "");
try {
Rs1. Open (Mysql,conn);
}
catch (ex) {
var errstr,errstr0,errstr1= "==>" +new Date () + "<br/>";
ERRSTR0 = "Error:" +ex+ "<br/>" +MYSQL;
var o = conn. Errors;
for (Var i=0;i<o.count;i++)
{
ERRSTR1 + = O.item (i). Number + ":" + o.item (i). Description+ "," +o.item (i). Sqlstate+ ";" +o.item (i). Source;
}
Errstr =errstr0+ "<br/>" +ERRSTR1;
O.clear ();
Response.Write ("<br/>" + Errstr + "");
}
if (rs1. State==1)
{
if (!) ( Rs1. BOF && rs1. EOF))
{
ret = rs1 (0). value;
}
Rs1. Close ();
}
return ret;
}
var Class = {
Create:function () {
return function (n) {
This.initialize.apply (this, arguments);
}
}
}
var TABLE = Class.create ();
Table.prototype = {
initialize:function (tabname) {
this. TabName = tabname;
this. Fields=[];
this. FieldCount = 0;
this.values=[];
this.types=[];
this. Mysql= "";
This.flag;
},
f:function (s)
{
var a=s.split (",");
for (var i=1;i<a.length;i++)
{
this. Fields[i-1]=a[i];
}
this. FieldCount = a.length-1;
},
v:function (s)
{
var a=s.split (",");
This.flag=a[0];
for (var i=1;i<a.length;i++)
{
This.values[i-1]=a[i];
}
if (a[0]==1) this. Replace ();
if (a[0]==2) this. Insert ();
if (a[0]==3) this. Update ();
if (a[0]==4) this. Delete ();
},
replace:function ()
{
if (this.values[0]==0)
this. Insert ();
Else
this. Update ();
},
insert:function ()
{
var fs= "", vs= "";
var j=0; I,j may not be synchronized, some column values may be empty, indicating that their values are not inserted, to ensure that the syntax of the SQL is correct
for (Var i=0;i<this. fieldcount;i++)
{
if (this.values[i] = = "NULL") continue;
if (j = = 0)
{
fs = this. Fields[i];
vs + + "' +this.values[i]+" ";
} else
{
fs = "," +this. Fields[i];
vs + = ", '" +this.values[i]+ "";
}
J + +;
}
this. Mysql= "INSERT into" +this. Tabname+ "(" +fs+ ") VALUES (" +vs+ ");
},
update:function ()
{
this. mysql= "Update" +this. Tabname+ "Set";
for (Var i=1;i<this. fieldcount;i++)
{
if (this.values[i] = = "NULL")
{
if (I!= 1) this. MySQL + = ",";
this. MySQL = this. fields[i]+ "=null";
} else
{
if (I!= 1) this. MySQL + = ",";
this. MySQL = this. fields[i]+ "= '" "+this.values[i]+" ";
}
}
this. MySQL = "where" +this. fields[0]+ "= '" "+this.values[0]+" ";
},
delete:function ()
{
this. Mysql= "Delete from" +this. Tabname+ "where";
var j=0; I,j may not be synchronized, some column values may be empty, indicating that they are not conditional, to ensure that the syntax of the SQL is correct
for (Var i=0;i<this. fieldcount;i++)
{
if (this.values[i]== "") continue;
if (this.values[i] = = "NULL")
{
if (J!= 0) this. MySQL = "and";
this. MySQL = this. Fields[i]+ "is null";
} else
{
if (J!= 0) this. MySQL = "and";
this. MySQL = this. fields[i]+ "= '" "+this.values[i]+" ";
}
J + +;
}
}
};
var fso, TS, S;
var ForReading = 1, ForWriting = 2;
var name;//= "C:webyafulwisadtt.csv";
Name = Server.MapPath ("T.csv");
var fso = new ActiveXObject ("Scripting.FileSystemObject");
if (FSO). FileExists (name))
{
Response.Write ("file" +name+ exists!) ");
TS = fso. OpenTextFile (name, ForReading, true);
Ts. SkipLine ();
var data=new TABLE (Request.QueryString ("a") + "");
s = ts. ReadLine ();
Data. F (s);
Response.Write ("<br/>" +data). FieldCount);
Response.Write ("<br/>" + s.replace (/,/g, "T") + "");
Response.Write ("<br/>" + data. Fields + "");
while (!ts. AtEndOfStream)
{
s = ts. ReadLine ();
Response.Write ("<br/>" + s.replace (/,/g, "T") + "");
Data. V (s);
Response.Write ("<br/>" + data. MySQL + "");
RunSQL (data. MySQL);
}
Ts. Close ();
}
Else
{
Response.Write ("file" +name+) does not exist, please check the query after! ");
}
%>