如何使用临时表在多个C#调用 [英] How do I use a temp table across multiple c# calls

查看:163
本文介绍了如何使用临时表在多个C#调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#应用程序,使用ADO.Net连接MSSQL

I have a C# application, using ADO.Net to connect to MSSQL

我需要创建表(用列的动态数),然后插入很多记录,然后做一个选择背出表。

I need to create the table (with a dynamic number of columns), then insert many records, then do a select back out of the table.

每一步必须是一个单独的C#调用,虽然我可以保持连接/事务开放的时间。

Each step must be a separate c# call, although I can keep a connection/transaction open for the duration.

推荐答案

有两种类型的SQL Server中的临时表,局部临时表和全局临时表。从BOL:

There are two types of temp tables in SQL Server, local temp tables and global temp tables. From the BOL:

前缀单号(#tablename),并配有双号码前缀全局临时表名本地临时表的名称号(##表名)。

Prefix local temporary table names with single number sign (#tablename), and prefix global temporary table names with a double number sign (##tablename).

本地临时表将活的只是的当前连接。全局将可用于所有连接。因此,如果你再使用(和你没有说你可以)在您的相关调用同一个连接,你可以只使用一个本地临时表,而与对方的临时表干扰并发进程的后顾之忧。

Local temp tables will live for just your current connection. Globals will be available for all connections. Thus, if you re-use (and you did say you could) the same connection across your related calls, you can just use a local temp table without worries of simultaneous processes interfering with each others' temp tables.

您可以在 BOL文章 ,具体规定了关于一半,临时表一节。

You can get more info on this from the BOL article, specifically under the "Temporary Tables" section about halfway down.

祝您好运!

-f!

Best of luck!
-f!

这篇关于如何使用临时表在多个C#调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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