同一数据库中复制数据表。未测试完成

Sub CopyTable(PathName,TableName,TableName1)
response.Write("<br>数据库路径:"&PathName)
response.Write("<br>源数据表名称:"&TableName)
response.Write("<br>目标数据表名称:"&TableName1)
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(PathName)
set Conn=server.createobject("Adodb.connection")
On Error Resume Next
Conn.open strConn
strSql1 = "select * from "&TableName&" where 1=0"
rsSrc.open strSql1,conn,1,3

strSql = "create table "&TableName1&"("
response.Write(rsSrc.Fields(0).Type)
for i = 0 to rsSrc.Fields.Count - 1
    select case rsSrc.Fields(i).Type
  case 2
  strSql = strSql&rsSrc.Fields(i).Name&" short,"
        case 3
   if rsSrc.Fields(i).Properties("ISAUTOINCREMENT") = True then
  strSql = strSql&rsSrc.Fields(i).Name&" Autoincrement,"
   else
  strSql = strSql&rsSrc.Fields(i).Name&" integer,"
   end if
  case 4'单精度数字
  strSql = strSql&rsSrc.Fields(i).Name&" real,"
  case 5'双精度数字
  strSql = strSql&rsSrc.Fields(i).Name&" double,"
  case 6'货币
  strSql = strSql&rsSrc.Fields(i).Name&" Currency,"
  case 7'日期时间
  strSql = strSql&rsSrc.Fields(i).Name&" datetime,"
  case 11'是/否
  strSql = strSql&rsSrc.Fields(i).Name&" YesNo,"
  case 17'字节型数字
  strSql = strSql&rsSrc.Fields(i).Name&" byte,"
  case 72'同步复制ID数字
  strSql = strSql&rsSrc.Fields(i).Name&" guid,"
        case 131'带小数点数字
  strSql = strSql&rsSrc.Fields(i).Name&" Numeric,"
  case 202'文本
  strSql = strSql&rsSrc.Fields(i).Name&" varchar,"
  case 203'备注/超级链接
  strSql = strSql&rsSrc.Fields(i).Name&" memo,"
  case 205'OLE对象
  strSql = strSql&rsSrc.Fields(i).Name&" OLEObject,"
  case 129 
            strSql = strSql&rsSrc.Fields(i).Name&" char("&CStr(rsSrc.Fields(i).DefinedSize)&"),"
        case else
      response.write("<script>alert('数据表"&tablename&"表中字段 "&rsSrc.Fields(i).Name&" 类别"&rsSrc.Fields(i).Type&"错误 ,系统即将返回');location.href='CopyTable.asp';</script>")
   Response.end
      end select
next
strSql = Left(strSql,Len(strSql)-1)&")"
rsSrc.Close
response.Write(strSql)
response.End()
conn.execute(strSql)
conn.close
set Conn=nothing
response.write("<script>alert('数据从表"&tablename&"到表"&TableName1&" 复制成功 ,系统即将返回');location.href='CopyTable.asp';</script>")
Response.end
End Sub

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页