none
How to get Data in to Data Table after executing the sp_executeSql stored Procedure. RRS feed

  • Question

  • I am working on a windows form application. How can I get Data in to my windows application by executing the sp_executeSql either by using connected or disconnected architecture. How can we get Data without writing any new function,

    • Moved by Tina-Shi Thursday, May 7, 2015 5:53 AM the issus is related to this ADO.NET
    Wednesday, May 6, 2015 7:40 AM

Answers

  • Hello Datta Sai Krishna,

    >> How can I get Data in to my windows application by executing the sp_executeSql either by using connected or disconnected architecture

    For a disconnected architecture:

    You could try:

    SqlConnection con = new SqlConnection(@"Server=(localdb)\Projects;Database=DFDB;Trusted_Connection=true;"); string sql = "N'select * from [Order]'"; try { con.Open(); SqlCommand cmd = new SqlCommand(string.Format("sp_executeSql {0}", sql), con); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); }

    catch(Exception ex)

    {

    Console.WriteLine(ex.Message);

    } finally { con.Close(); }

    For a connected architecture

    You could try:

    SqlConnection con = new SqlConnection(@"Server=(localdb)\Projects;Database=DFDB;Trusted_Connection=true;"); string sql = "N'select * from [Order]'"; try { con.Open(); SqlCommand cmd = new SqlCommand(string.Format("sp_executeSql {0}", sql), con); //DataSet ds = new DataSet(); //SqlDataAdapter da = new SqlDataAdapter(cmd); //da.Fill(ds); SqlDataReader reader = cmd.ExecuteReader(); while (reader.HasRows) { //populate data into the datatable row by row } } catch(Exception ex)

    {

    Console.WriteLine(ex.Message);

    } finally { con.Close(); }

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, May 7, 2015 6:25 AM
    Moderator

All replies

  • Hi Datta,

    Thank you for posting in MSDN forum.

    Since this issue is related to this ADO.NET DataSet, so we will move this case to this ADO.NET DataSet forum, you will get better support.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 7, 2015 5:53 AM
  • Hello Datta Sai Krishna,

    >> How can I get Data in to my windows application by executing the sp_executeSql either by using connected or disconnected architecture

    For a disconnected architecture:

    You could try:

    SqlConnection con = new SqlConnection(@"Server=(localdb)\Projects;Database=DFDB;Trusted_Connection=true;"); string sql = "N'select * from [Order]'"; try { con.Open(); SqlCommand cmd = new SqlCommand(string.Format("sp_executeSql {0}", sql), con); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); }

    catch(Exception ex)

    {

    Console.WriteLine(ex.Message);

    } finally { con.Close(); }

    For a connected architecture

    You could try:

    SqlConnection con = new SqlConnection(@"Server=(localdb)\Projects;Database=DFDB;Trusted_Connection=true;"); string sql = "N'select * from [Order]'"; try { con.Open(); SqlCommand cmd = new SqlCommand(string.Format("sp_executeSql {0}", sql), con); //DataSet ds = new DataSet(); //SqlDataAdapter da = new SqlDataAdapter(cmd); //da.Fill(ds); SqlDataReader reader = cmd.ExecuteReader(); while (reader.HasRows) { //populate data into the datatable row by row } } catch(Exception ex)

    {

    Console.WriteLine(ex.Message);

    } finally { con.Close(); }

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, May 7, 2015 6:25 AM
    Moderator

  • Just an FYI here ... DataAccess should never be included directly in the UI. See my blog post about Multi-tier applications:

    http://geek-goddess-bonnie.blogspot.com/2010/10/multi-tier-applications.html

    May I suggest reading some of my blog posts about DataAccess, DataSets and Databinding ...

    First, check out my 3-part series on Data Access for some basic ideas. I'm using a SQL database, but the same would apply to other databases (except you'd use OleDb classes instead of Sql classes):

    http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html

    Each post adds extra complexity to the Data Access classes, but more flexiblity. The first post is enough to get you going in the right direction and give you a general idea of the concept, but the second post is more useful. The third post gets into using anonymous delegates and may be too much for a beginner. (which, to be honest, I don't use the anonymous delegates anymore, but I used to on previous projects several years ago)


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Saturday, May 9, 2015 4:17 PM
  • Its not working. When I passed the parameter in command itself, It is showing error @statement parameter required.
    Tuesday, May 12, 2015 10:28 AM
  • Could you show us the bit of code where you're having the problem?

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Tuesday, May 12, 2015 1:42 PM
  • Don't tell nonsense there is no parameter in the code from Fred.

    If you have another question make than simply a new question where you show the code which gives the error.



    Success
    Cor

    Tuesday, May 12, 2015 2:22 PM