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

    Pass value dynamic in main column

    Here Main_Column_Names Column we are reterive two values (RS_BRANCH_CODE and BRANCH_CODE) And below my code i am just pass two value on index[0] & index[1].


    var Main_Column_Names = ConfigurationManager.AppSettings["Main_Column_Name"].Split(',').Select(s => s.Trim()).ToList();

    try
    {
    copylist = dtexcel.AsEnumerable().Select(s => s.Field<string>(Main_Column_Names[0])).Distinct().ToList();
    strSelectedMainColName = Main_Column_Names[0];
    }

    catch (Exception ex)
    {
    copylist = dtexcel.AsEnumerable().Select(s => s.Field<string>(Main_Column_Names[1])).Distinct().ToList();

    strSelectedMainColName = Main_Column_Names[1];
    }

    I do not want Main_Column_Names[0] or Main_Column_Names[1] , i want pass Main_Column_Names[] dynamically. how i can do it.
  • #768989
    Hai Nitin,
    I think you can use foreach loop and pass the collection as below:

    var Main_Column_Names = ConfigurationManager.AppSettings["Main_Column_Name"].
    Split(',').Select(s => s.Trim()).ToList();
    try
    {
    foreach(var colName in Main_Column_Names)
    {
    copylist = dtexcel.AsEnumerable().Select(s => s.Field<string>(colName)).
    Distinct().ToList();
    strSelectedMainColName = colName;
    }
    }
    catch (Exception ex)
    {
    throw ex;
    }

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768996
    Hi,

    I agree with Pawan, if you want to assign values with different rows dynamically then you have to loop each row and assign it as per you need.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #769030
    You can use this Procedure to Pass value dynamic in main column in MySQL
    CREATE PROCEDURE AvgCityProcedure(
    IN colName VARCHAR(100),
    OUT colAvg FLOAT)
    BEGIN
    SET @c1 = 0.0;
    SET @M:= colName;
    SET @QUERY:= CONCAT('SELECT AVG(',@M,') INTO @C1 FROM DemoTable');
    PREPARE stmt FROM @QUERY;
    EXECUTE stmt;
    SET colAvg:=@C1;
    SELECT colAvg;
    END


Sign In to post your comments