-1

So I'm working with NopCommerce this last month but I'm trying to make a tour website and it's kinda hard so I have a code that connects to the DB and makes a SELECT :

public string cs_preorder_proc(int opcode, string p1, string p2)
{
    string reto1 = "**";

    String connectionString = "connectionstring";
    //String sql = "SELECT * FROM dbo.OrderRecord";
    String sql = "SELECT * FROM dbo.CS_Orders";

    var model = new List<Product>();

    //using (SqlConnection conn = new SqlConnection(connectionString))
    SqlConnection conn = new SqlConnection(connectionString);

    SqlCommand cmd = new SqlCommand(sql, conn);

    conn.Open();

    SqlDataReader rdr = cmd.ExecuteReader();

    bool b1 = true;

    int itotraws = 0;
    int itotporpag = 50;

    while (b1 && itotraws < itotporpag)
    {
        itotraws ++;

        b1 =rdr.Read();

        if (b1)
        {
            string a1 = "";
            string a2 = "";
            string a3 = "";
            string a4 = "";
            string a5 = "";
            string a6 = "";

            a1 = rdr["ProductName"].ToString();
            a2 = rdr["Price"].ToString();
            a3 = rdr["PersonsNumber"].ToString();
            a4 = rdr["Date"].ToString();
            a5 = rdr["TourType"].ToString();
            a6 = rdr["CarsNumber"].ToString();
        }
    }

    return reto1;
}

Now I want to show that in a new View , but I don't know if I need to create a model with get ; set or it exists a better way to do this.

ekad
  • 14,436
  • 26
  • 44
  • 46

1 Answers1

0

Just create model with all object

public partial class MyClass{
    public string ProductName {get;set;}
    public string Price {get;set;}
    public string PersonsNumber {get;set;}
    public DateTime Date {get;set;}
    public string TourType {get;set;}
    public string CarsNumber {get;set;}
}

which are required and you need use in view page

Map all data in list of new created model(MyClass - IList<MyClass>) and pass list model to view.

Raju Paladiya
  • 778
  • 2
  • 12
  • 35
  • Question is not really about *how to create Model with getter and setter*, perhaps OP wants to bind model and show the properties to the view page.. Because everyone knows how to create a model, isn't it? – Divyang Desai Jun 28 '18 at 04:57
  • @Div - He said "Now I want to show that in a new View , but i don´t know if i need to create a model with get ; set or it exists a better way to do this.", I'm not said How to create Model, I just write it for his help and understanding. :D – Raju Paladiya Jun 28 '18 at 05:00
  • *I'm not said How to create Model*, I would strongly encourage you to read your answer again. *I just write it for his help and understanding.* Doesn't make any sens with OP's question really, this should be a comment instead. – Divyang Desai Jun 28 '18 at 05:04