Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am getting the list of brands from sqlite3 database,you can see in BrandCodes function, I have written new function Brands(), I don't know how to assign BRCode and BRText to this result. Is this the right approach. Please help me, guys. I know how to use in C#.

C++
SortedList *Util::BrandCodes()
{
    SortedList *list = new SortedList();

    IDbCommand    *command = 0;
    IDataReader *reader = 0;

    command = m_dbConnection->CreateCommand();
    command->CommandText = S"SELECT * FROM BrandData";
    reader = command->ExecuteReader();
            // Read all records
    while( reader->Read() )
    {
        // Add item to the map [ market_id, description ]
        list->Add( reader->Item[ S"BRCode" ]->ToString(),
        String::Format(S"{0}({1})",GetFieldValue(reader,S"BRText"),GetFieldValue(reader,S"BRCode")));
    }
    Brands();
    return list;
}

String *FuelUtil::Brands( ) __gc[]
{
    String *result __gc[];
    result = 0;
    SortedList  *brandList = 0;

    if (brandList == 0)
    {
        brandList = GetBrandCodes();            
    }       

    for (int i =0; i<= brandList->Count; i++)
    {
        result = new String * __gc[2];
        // how to assign BRCode and BRText to this result
        //result[0] = 
        //result[1] = 
    }

    return result;
}


What I have tried:

I tried this way

C++
String *FuelUtil::Brands( ) __gc[]
{
    String *result __gc[];
    result = 0;
    SortedList  *brandList = 0;

    if (brandList == 0)
    {
        brandList = GetBrandCodes();            
    }       

    for (int i =0; i<= brandList->Count; i++)
    {
        result = new String * __gc[2];
        // how to assign BRCode and BRText to this result
        //result[0] = 
        //result[1] = 
    }

    return result;
}
Posted
Updated 4-Oct-17 18:33pm
v2

1 solution

Fistly, I'm not sure if you're doing this right.
Looks like you're using managed C++ in which case you should be using SortedList^ instead of SortedList* and also gcnew instead of new.

You should be able to get the value inside the for loop using - brandList->Values[i];
This would of course return a string in the format "BRText(BRCode)" like you inserted into the list.

You will then need to split it into separate strings using String::Split Method (array<char>^)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900