asp.net 通过后台Javascript 上传表数据
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 += ",";
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<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:\\web\\yafulwisad\\t\\t.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("<br/>"+data.FieldCount);
Response.Write("<br/>" + s.replace(/,/g,"\t") + "");
Response.Write("<br/>" + data.Fields + "");
while (!ts.AtEndOfStream)
{ www.zzzyk.com
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(" 文件 "+name+" 不存在,请核对后查询!");
补充:Web开发 , ASP.Net ,
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- jsp+javaBean中Column 'ordersPrice' specified twice的错误
- Java TCP/IP Socket网络编程系列
- 大家来讨论一下我到底该用什么好?Swing 还是 JavaFX
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- spring 获取上下文问题
- SSH 导入导出excel 谁有这块的资料吗?
- Ext TreePanel 刷新问题
- springmvc 加载一个jsp页面执行多个方法 报404
- checkbox数组action怎么向页面传值