Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共4 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:[求助][讨论] 如何在数据库上创建临时表

1楼
252476276 发表于:2024/5/8 15:10:00
    如何在执行过程中,创建一个已有表的相似临时表

    Dim cmd As New SQLCommand
    cmd.ConnectionName = strSource
    cmd.CommandText = "se lect * into #new" & strTableName & strUser & " from  (sel ect * from " & strTableName & " where 1=0) as a"
    cmd.ExecuteNonQuery()
    Output.Show("123")

commandtext 复制到MS-SQL中可以运行,也能执行,也可以查询到这个临时表

但执行程序时报以下错误

事件/函数:
无法完成延迟准备。
无法预定义语句。
对象名 'newKPInodeSet100262' 无效。
   在 System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr)
   在 System.Data.OleDb.OleDbDataReader.BuildSchemaTableRowset(Object handle)
   在 System.Data.OleDb.OleDbDataReader.GenerateSchemaTable(OleDbDataReader dataReader, Object handle, CommandBehavior behavior)
   在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.FillSchemaInternal(DataSet dataset, DataTable datatable, SchemaType schemaType, IDbCommand command, String srcTable, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.FillSchema(DataTable dataTable, SchemaType schemaType, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.FillSchema(DataTable dataTable, SchemaType schemaType)
[此贴子已经被作者于2024/5/8 15:10:25编辑过]
2楼
有点蓝 发表于:2024/5/8 15:19:00
这种方式创建的临时表是有使用限制的,只能在创建的上下文里使用

建议使用存储过程,在存储过程里创建表,然后继续后续的操作
3楼
252476276 发表于:2024/5/8 15:37:00
需要创建临时表,给sqlBulkCopy写入数据,存储过程创建了,就看不到了
4楼
有点蓝 发表于:2024/5/8 15:43:00
sqlBulkCopy只能使用数据表,不能使用临时表
共4 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .01563 s, 2 queries.