WEB开发网
开发学院WEB开发ASP.NET .net 通过后台js上传表数据 阅读

.net 通过后台js上传表数据

 2012-12-29 16:14:18 来源:WEB开发网   
核心提示: Upload.aspx:<%@ LANGUAGE='JAVASCRIPT' %><!-- #include file = "../adojvs.inc"--><!-- #include file = "../conn.inc"--&

 Upload.aspx:

<%@ LANGUAGE='JAVASCRIPT' %>
<!-- #include file = "../adojvs.inc"-->
<!-- #include file = "../conn.inc"-->
<%

// 执行SQL语句
//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可能并不同步,有些列值可能为空,表示不插入其值,要保证sql的语法正确
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 += ",";

1 2  下一页

Tags:net 通过 后台

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接