You must Sign In to post a response.
  • Category: .NET

    Generate class from stored procedure C#

    I have few sql procedures returns lot of tables. I want a way to automatically generate classes for procedure tables output. Every table should generate a class.
    How can i achieve this ?

    Thanks
    Anil
  • #766145
    Hi

    can you explain more . if you need in your procedure automatically generated from your cs file then call method?

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766146
    I am calling stored procedure from C# and and stored procedure output is containing in data set with multiple data tables. Now i want to generate class structure for every data table. No need data just only structure.
    anil jain,
    Software Developer,
    NEITL,Mumbai.

  • #766147
    Hi
    Ofcourse

    Dataset -> Collection of Datatable.

    So you do one thing retrieve in your datatable to assign Dataset

    then use this code for extract separate datatable

    Dataset ds=new Dataset();

    Table1
    ========
    ds.Tables[0]

    Table2
    ========
    ds.Tables[1]

    then use and process.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766148
    Hi

    If you need merge all datatable means try this code which i mention below


    DataTable dt = new DataTable();
    DataRow dr = null;
    dt.Columns.Add("Id", typeof(int));
    dt.Columns[0].AutoIncrementSeed = 1;
    dt.Columns[0].AutoIncrement = true;
    dt.Columns.Add("Name");
    dt.Columns.Add("Employer");
    dr = dt.NewRow();
    dr["Name"] = "DNS";
    dr["Employer"] = "ASP.NET";
    dt.Rows.Add(dr);


    DataTable dt2 = new DataTable();
    DataRow dr1 = null;
    dt2.Columns.Add("Id", typeof(int));
    dt2.Columns[0].AutoIncrementSeed = 1;
    dt2.Columns[0].AutoIncrement = true;
    dt2.Columns.Add("Name");
    dt2.Columns.Add("Employer");
    dr1 = dt2.NewRow();
    dr1["Name"] = "Kumar";
    dr1["Employer"] = "Dotnet Developer";
    dt2.Rows.Add(dr1);
    dt2.Merge(dt);
    dt2.AcceptChanges();

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766180
    Hi
    You can use either one of the following method
    1. use of dataset :- which will access data say multiple table from database and you can generate c# classes on fly using table collection of dataset
    2. 2nd apporch will be you can create class using EF (Data First appoch) . The class can be generated depend upon database structure
    you can refer http://www.tutorialspoint.com/entity_framework/entity_database_first_approach.htm
    url

    Thanks
    Umesh Bhosale


Sign In to post your comments