.net 通过后台js上传表数据
来源: 阅读:718 次 日期:2014-08-29 11:01:32
温馨提示: 小编为您整理了“.net 通过后台js上传表数据”,方便广大网友查阅!

Upload.aspx:

<%@ LANGUAGE='JAVASCRIPT' %>

<%

// 执行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("
" + MySQL + "");

try {

rs1.Open(MySQL,conn);

}

catch (ex) {

var ErrStr,ErrStr0,ErrStr1="==>"+new Date()+"
";

ErrStr0 = "Error:"+ex+"
"+MySQL;

var o = conn.Errors;

for (var i=0;i

{

ErrStr1 += o.Item(i).Number + ":" + o.Item(i).Description+", "+o.Item(i).SQLState+";"+o.Item(i).Source ;

}

ErrStr =ErrStr0+"
"+ErrStr1;

o.Clear();

Response.Write("
" + 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

{

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

{

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

{

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

{

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可能并不同步,有些列值可能为空,表示不以其为条件,要保证sql的语法正确

for(var i=0;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(" 文件 "+name+" 存在!");

ts = fso.OpenTextFile(name, ForReading, true);

// ts.SkipLine();

var data=new TABLE(Request.QueryString("a")+"");

s = ts.ReadLine();

data.F(s);

Response.Write("
"+data.FieldCount);

Response.Write("
" + s.replace(/,/g,"t") + "");

Response.Write("
" + data.Fields + "");

while (!ts.AtEndOfStream)

{

s = ts.ReadLine();

// Response.Write("
" + s.replace(/,/g,"t") + "");

data.V(s);

Response.Write("
" + data.MySQL + "");

RunSQL(data.MySQL);

}

ts.Close();

}

else

{

Response.Write(" 文件 "+name+" 不存在,请核对后查询!");

}

%>

更多信息请查看IT技术专栏

更多信息请查看 网络编程
手机网站地址: .net 通过后台js上传表数据
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们| 联系我们| 人才招聘| 网站声明| 网站帮助| 非正式的简要咨询| 简要咨询须知| 加入群交流| 手机站点| 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:
咨询QQ:526150442(9:00—18:00) 版权所有:
云南网警报警专用图标
Baidu
map