none
Stored procedure not returning data in C# RRS feed

  • Question

  • hi ,

    i am using following code to get data from sql server

    SqlConnection con = new SqlConnection(connectionstring);
    
    cmd.CommandType = CommandType.StoredProcedure;  
    
    cmd.CommandText = "select_upcoming_events";    
    
    cmd.Connection = con;        
    
    SqlDataAdapter da = new SqlDataAdapter(cmd);  
    
    DataSet ds = new DataSet();   
    
    da.Fill(ds,"demo");           
    
    return ds;

     i have used following stored procedure. the store proc working fine in my sql server. but when i use in c# code it is not returning table data

    begin
    select * from Event WHERE Start_Date >= CAST(GETDATE() AS DATE)
    end

    above proc  is displaying data in sql server. but in asp.net page i am getting null data

    please help in this


    thanks, prathap If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, June 7, 2013 9:42 AM

Answers

  • hi ,

    i am using following code to get data from sql server

    SqlConnection con = new SqlConnection(connectionstring);
    
    cmd.CommandType = CommandType.StoredProcedure;  
    
    cmd.CommandText = "select_upcoming_events";    
    
    cmd.Connection = con;        
    
    SqlDataAdapter da = new SqlDataAdapter(cmd);  
    
    DataSet ds = new DataSet();   
    
    da.Fill(ds,"demo");           
    
    return ds;

     i have used following stored procedure. the store proc working fine in my sql server. but when i use in c# code it is not returning table data

    begin
    select * from Event WHERE Start_Date >= CAST(GETDATE() AS DATE)
    end

    above proc  is displaying data in sql server. but in asp.net page i am getting null data


    And how did you found out it was because of the code above. What do you do with the returned data. In other words, did you debug this and are you sure it does return nothing?

    Success
    Cor


    Saturday, June 8, 2013 10:02 AM
  • above proc  is displaying data in sql server. but in asp.net page i am getting null data

    At the very least, you would not be getting a "null", you'd get an empty DataSet if the call to the stored proc didn't return any data. So perhaps you didn't actually mean "null"?

    As Cor asked, how are you calling this method and what are you doing with the returned object?


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Saturday, June 8, 2013 3:36 PM

All replies

  • I hope you miss the connection line. Please check the following line in your code

    cmd.Connection = con;


    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    Friday, June 7, 2013 10:47 AM
  • hi sambath,

    it is there in above code


    thanks, prathap If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, June 7, 2013 11:04 AM
  • hi ,

    i am using following code to get data from sql server

    SqlConnection con = new SqlConnection(connectionstring);
    
    cmd.CommandType = CommandType.StoredProcedure;  
    
    cmd.CommandText = "select_upcoming_events";    
    
    cmd.Connection = con;        
    
    SqlDataAdapter da = new SqlDataAdapter(cmd);  
    
    DataSet ds = new DataSet();   
    
    da.Fill(ds,"demo");           
    
    return ds;

     i have used following stored procedure. the store proc working fine in my sql server. but when i use in c# code it is not returning table data

    begin
    select * from Event WHERE Start_Date >= CAST(GETDATE() AS DATE)
    end

    above proc  is displaying data in sql server. but in asp.net page i am getting null data


    And how did you found out it was because of the code above. What do you do with the returned data. In other words, did you debug this and are you sure it does return nothing?

    Success
    Cor


    Saturday, June 8, 2013 10:02 AM
  • above proc  is displaying data in sql server. but in asp.net page i am getting null data

    At the very least, you would not be getting a "null", you'd get an empty DataSet if the call to the stored proc didn't return any data. So perhaps you didn't actually mean "null"?

    As Cor asked, how are you calling this method and what are you doing with the returned object?


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Saturday, June 8, 2013 3:36 PM
  • I think you are testing with Start_Date having GETDATE which returns current date. So the moment you hit the stored proc there might be no record in database with Start Date greater or equal to current date. Just check your stored proc with a date in the past

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Tuesday, June 11, 2013 9:02 AM