我可以使用ADO组件创建一个表作为选择吗? [英] Can i create a table as select, using ado component?

查看:58
本文介绍了我可以使用ADO组件创建一个表作为选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试在运行时创建表,但是此新表必须具有与源表相同的定义.

我的问题是这样的:
我正在将文件导入到表中,但是我想将文件信息发送到临时表中,然后与我的最终表合并.

困难的部分是我使这种机制非常自动化,并且我可以配置要发送到最终表的列...并且如果有人将列添加到新表中,则我的过程必须从文件中复制信息到临时表,然后将其发送到最终表.临时表不受任何人管理,该过程必须创建新列.

因此,我的想法是将temp表放在过程的最后,并在每次运行过程时进行创建...

我试图以ExecuteNonQuery的身份运行我的查询,但是我对其进行了选择,这会使编译器引发错误,并且如果我尝试以ExecuteReader的身份运行,我在选择"上也会遇到相同的问题(关键字"select"附近的语法不正确) ''.)

有人可以帮忙吗?

顺便说一句即时通讯使用C#.

Hi,

I''m trying to create a table on runtime, but this new table has to have the same definition as the source table.

My problem is this:
i''m importing a file to a table, but i wanto to send the file information to a temporary table and then merge with my final table.

the difficult part is that i have this mechanism very automated, and i can configure the columns that i want to send to the final table... and if someone adds columns to the new table, my process has to copy the information from the file, to the temporary table and after that send it to the final table. the temporary table isnt managed by anyone, and the process has to create the new columns.

So, my idea is to drop the temp table on the end of my process and create every time that i run my process...

i tried to run my query as ExecuteNonQuery, but i have an select on it that makes the compiler raise an error, and if i try to run as ExecuteReader i have the same problem on "select" (Incorrect syntax near the keyword ''select''.)

can anyone help on this?

BTW im using C#. this is suppose to be a windows services.

推荐答案

创建如下所示的dyn查询并执行
您的新表格将根据您的动态结构进行创建

选择top 0 null作为Col1,将null作为Col2插入[TempNewTable]
否则

从Maintable中选择top 0 Col1,Col2到[TempNewTable]
(如果需要适当的数据类型,这会更合适)
Create a dyn query like below and execute
your new table will be created as per ur dynamic structure

select top 0 null as Col1,null as Col2 into [TempNewTable]
Or else

select top 0 Col1 ,Col2 into [TempNewTable] from Maintable
(this will be more appropriate if need data type proper)


这篇关于我可以使用ADO组件创建一个表作为选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆