I have checked the above query. The only reason should be parameters would be incorrect or no records matches the corresponding parameters.
I tried with below scripts and code. Its working. check with this,
DB----
Create table branch
(branch_id int,
branch_name varchar(10)
)
Create table Acadamic_year
(academic_year_id int,
academic_year_from int,
academic_year_to int)
insert into branch values(1,'MSC')
insert into Acadamic_year values(1,2012,2013)
alter procedure [dbo].[temptable] (@branchid int,@academicyearid int)
as
begin
set nocount on
declare @branchname varchar(50)
declare @acfy int ;
declare @acty int
select @branchname=Branch_name from Branch where Branch_id=@branchid
select @acfy=Academic_year_from,@acty=Academic_year_to from Acadamic_year where Academic_year_id=@academicyearid
create table #temptable(Brach_name varchar(10),Acadamic_year_from smallint,Acadamic_year_to smallint)
insert into #temptable(Brach_name,Acadamic_year_from,Acadamic_year_to)values(@branchname,@acfy,@acty)
select * from #temptable
end
--exec temptable 1,1
C# code:
public partial class Form1 : Form
{
private SqlConnection con;
public Form1()
{
InitializeComponent();
con = new SqlConnection("Data Source=localhost\\sqlexpress; Initial Catalog=Cricket; Integrated Security=SSPI;");
}
private void Form1_Load(object sender, EventArgs e)
{
int r=1;
int s=1;
SqlCommand cmd = new SqlCommand("temptable", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@branchid", r));
cmd.Parameters.Add(new SqlParameter("@academicyearid", s));
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "#temptable1");
DataTable dt = ds.Tables["#temptable1"];
}
}