First i am execute procedure for create #temp table with data in first, then after i want #temp some column with other table column using joins. first query is execute after that on second query error occur (#temp object is invalid)
if (con.State == ConnectionState.Closed)
{ con.Open(); }
IsInTransaction = true;
trans = con.BeginTransaction();
da = new SqlDataAdapter("Execute SP_Statement_Temp", con);
da.SelectCommand.Transaction = trans;
DataTable DatTemp = new DataTable();
da.Fill(DatTemp);
SelectString = "Select Distinct #temp.IdentityID, TblMasterTypeOfIdentity.TypeOfIdentity,TblIdentity.IdentityName, '' As 'Opening Balance' , '' As 'Closing Balance' from #temp inner join TblIdentity on TblIdentity.IdentityID=#temp.IdentityID inner join TblMasterTypeOfIdentity on TblMasterTypeOfIdentity.TypeOfIdentityID=#temp.TypeOfIdentityID";
CmdString = SelectString + " " + WhereString + " " + OrderBy;
da = new SqlDataAdapter(CmdString, con);
da.SelectCommand.Transaction = trans;
DataTable datDetail = new DataTable();
da.Fill(datDetail);
trans.Commit();
IsInTransaction = false;
con.Close();