Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi all,

I have some doubts regarding temp tables in sqlserver
(1) Is it possible to create a temporary table programatically (using asp.net code) without using stored procedures , if yes please provide me code
Posted

You might either use SQL Server temporary tables[^] or just programmatically create a (disconencted) DataTable.
None of the above approaches require a stored procedure.
 
Share this answer
 
Comments
Praveen_P 31-Jan-14 5:59am    
Thanks , 5!
CPallini 31-Jan-14 6:16am    
You are welcome.
Refer:
How to create a temporary table in C#[^]
Hope this will help.
 
Share this answer
 
v2
Comments
Praveen_P 31-Jan-14 5:59am    
Thanks Githanjali , its working
Gitanjali Singh 31-Jan-14 6:02am    
Welcome :)
execute this

SQL
create table #table1(id bigint,name nvarchar(max))

insert into #table1(id,name)values (1,'xx')

insert into #table1(id,name)values (2,'yy')

select *fro #table1
 
Share this answer
 
also try like this:-

SqlConnection conn = new SqlConnection("connection string");
SqlCommand cmd = new SqlCommand("create table #MyTempTable(Stud_Id int, Column1 varchar(50))", conn);
conn.Open();
cmd.ExecuteNonQuery();
SqlBulkCopy bulkCopy = new SqlBulkCopy(conn);
bulkCopy.DestinationTableName = "#MyTempTable";
bulkCopy.WriteToServer(dt);
conn.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900