none
HOWTO Specify Lync/DataSet columns/table in select and order-by from a string. RRS feed

  • Question

  • Please help,

    How can one specify the "select" and "order-by" columns and the table to a Lync call, that come from a string;
    where the Lync is to a DataSet object?

    Example:

    In T-SQL one could do this:

    string csSelectColumns = "A, B, [C], [D]";
    string csOrderColumns = "A desc, [D] asc";
    string csTable = "MyTable";

    string csQRY = "select " + csSelectColumns + " from " + csTable + " order by " + csOrderColumns;

    How can one take the above for a DataSet object, and use the columns in the select, order-by, and table.

    Tuesday, January 26, 2016 7:28 PM

Answers

  • Thanks for the reply, but its not the answer I need.

    In fact, after more investigation, the Lync is simply NEVER going to work to solve my needs.

    I'm going to close this thread, and start a new one to see if anyone has a full "T-SQL" toolkit for DataSet's, or something, that does not require installing a database.

    • Marked as answer by J-S-B Wednesday, January 27, 2016 2:59 PM
    Wednesday, January 27, 2016 2:59 PM

All replies

  • var resultat = table.AsEnumerable().Where(i => i.Field<string>("A") == "something")

    .OrderBy(i => i.Field<string>("B")).ToList();


    returns a list off all the element that match the condition and orders it by column B;

    Hope it helps. Spiri

    Tuesday, January 26, 2016 8:00 PM
  • Thanks for the reply, but sadly, that does not work with multiple columns in 1 string, for "select" or the "oder by":

    string csSelectColumns = "A, B, [C], [D]";
    string csOrderColumns = "A desc, [D] asc";


    Also, the "i.Field<string>("B"))." requires one to know the data type like "<string>", and HARD-CODE that into the lync.
    • Edited by J-S-B Tuesday, January 26, 2016 10:06 PM
    Tuesday, January 26, 2016 9:52 PM
  • Hi J-S-B,

    Best regards,

    According to your description, you want to fill the data to dataset by using linq to sql, does it? I create a demo as below for your reference.

    class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                using (var db = new DemoDataDataContext())
    
                {
    
                    string csSelectColumns = "Name, Price, Category";
    
                    string csOrderColumns = "Name desc, Category asc";
    
                    string csTable = "[Products]";
    
                    string csQRY = "select " + csSelectColumns + " from " + csTable + " order by " + csOrderColumns;
    
                    var query = db.ExecuteQuery<ShowProd>(csQRY).ToList();
    
    
                    DataSet ds = new DataSet();
    
                    DataTable dt = new DataTable("Products");
    
                    dt.Columns.Add("Name", typeof(string));
    
                    dt.Columns.Add("Category", typeof(string));
    
                    dt.Columns.Add("Price", typeof(decimal));
    
                    foreach (var item in query)
    
                    {
    
                        DataRow dr = dt.NewRow();
    
                        dr["Name"] = item.Name;
    
                        dr["Price"] = item.Price;
    
                        dr["Category"] = item.Category;
    
                        dt.Rows.Add(dr);
    
                        //Console.WriteLine(item.Name);
    
                    }
    
                    ds.Tables.Add(dt);
    
                    Console.WriteLine(dt.Rows.Count);
    
                    Console.ReadLine();
    
                }
    
            }
    
        }
    
    
        class ShowProd
    
        {
    
            public string Category { get; set; }
    
            public string Name { get; set; }
    
            public decimal? Price { get; set; }
    
    }

    In addition, you could refer to following link about linq to sql to dataset.

    https://msdn.microsoft.com/en-us/library/bb386921(v=vs.110).aspx

    I hope it’s helpful to you.

    Best regards,

    Cole Wu


    Wednesday, January 27, 2016 5:41 AM
    Moderator
  • Thanks for the reply, but its not the answer I need.

    In fact, after more investigation, the Lync is simply NEVER going to work to solve my needs.

    I'm going to close this thread, and start a new one to see if anyone has a full "T-SQL" toolkit for DataSet's, or something, that does not require installing a database.

    • Marked as answer by J-S-B Wednesday, January 27, 2016 2:59 PM
    Wednesday, January 27, 2016 2:59 PM