Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cursors?
Message
 
 
À
04/10/2011 16:24:24
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Titre:
Divers
Thread ID:
01522833
Message ID:
01525576
Vues:
32
>>
>>The # temp tables are visible in the connection that created it. #Temp tables created in the stored procedure are not visible in the outside batch - they live only in the scope of the SP.
>
>Thanks. That's what I thought you had said but I am having a little trouble visualizing how to use it. Here's my problem: I want to construct a temporary table in the code behind of the webpage. The temporary table will be static (no editing, sorting etc.). The temporary table will then be displayed in a gridview on the page. So I have something like this in the markup:
><asp:GridView ID="GridView1" runat="server"  
>			AutoGenerateColumns="True" >
>			
>		</asp:GridView>
>
>
>and something like this in the code behind:
		Dim SQL As String
>		SQL = "SELECT * INTO #TempConstraint FROM " + SourceTableRBL.SelectedValue
>		Dim oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("TIPConnectionString").ConnectionString)
>		Dim oCommand As New SqlCommand(SQL, oConn)
>		oConn.Open()
>		oCommand.ExecuteNonQuery()
>
>So now that a temp table has been created, how can I get it into my gridview? And secondly, how or when do I dispose of the connection to avoid problems?

To get it into your GridView you will still need to select the data, so it's the same as 'SELECT * from ' + ... - no point of the temp table at all unless you want to re-use it for other statements (but since you don't have any conditions, I still don't see a point).

So, you will need oCommand.ExecuteReader() instead of NonQuery and you will need to do oConn.Close() as normal to close the connection.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform