Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
U

User 11196121

@User 11196121
About
Posts
22
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Create InputBox using VS2010 C++?
    U User 11196121

    hi all Has someone got sample codes (including description) on how to create an Inputbox in C++? Thanks in advance

    Managed C++/CLI c++ tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    No worries Richard, and please note that I do thank you for your overall support. Cheers

    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    Thanks Richard. i've therefore coded the calculation of standard deviation (see below). However results differ from Excel from the 3rd decimal point.Do you have any idea, as i have done it meticulously? I remembered someone working on sql server told me that depending on datatype used, computing 1/2 lead to a value close to 0.5 but still not 0.5. Do you think it might be an explanation, here? Cheers

    int obs;
    double mu, Ssigma, Svari, sum=0,sumsqr=0;

                     for (int i=1;i-1<dbdataset->Rows->Count-1;i++){
                         dbdataset->Rows\[i-1\]\["DataRet"\]=(System::Convert::ToDouble(dbdataset->Rows\[i-1\]\["Population"\])/System::Convert::ToDouble(dbdataset->Rows\[i\]\["Population"\])-1);
                         sum = sum + System::Convert::ToDouble(dbdataset->Rows\[i-1\]\["DataRet"\]);
                         obs = (dbdataset->Rows->Count-1);
                         mu = sum /obs;
                         sumsqr=sumsqr + pow((System::Convert::ToDouble(dbdataset->Rows\[i-1\]\["DataRet"\])-mu),2);
                         Svari=sumsqr/(obs-1);
                         Ssigma=sqrt(Svari);
                         lblvol->Text = Convert::ToString(Ssigma);
    
    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    Hi Richard Thanks. I've made a simple console app and can confirm that the String class does work and you could create string variables such as string codeproject without problem. However,based on facts it looks like a different story when dealing with c++/cli. Back to the main standard deviation calculation, i think it could not work as a columns can't directly be assigned to a type and treated like a variable (see below). it could have worked in vba by selecting the column range and perform the built-in functions: c++ sqrt() or math::sqrt(). Hence the solution of last resort: iterate through each row and perform the calculation in several steps (get the mean from "DataRet" column first, then carry out ... ) unless a you have a better idea. Cheers

    Error C2440: 'initializing' : cannot convert from 'System::Data::DataColumn ^' to 'double'

    DataTable^dbdataset=gcnew DataTable();
    DataColumn^rt_col=gcnew DataColumn();
    rt_col->ColumnName = "DataRet";
    rt_col->DataType=System::Type::GetType("System.Double");
    dbdataset->Columns->Add(rt_col);

                     sda->Fill(dbdataset);
    
                     double varet = dbdataset->Columns\["DataRet"\]; //already double type, no need System::Convert::ToDouble
                     double vola = sqrt(varet);
                     lblvol->Text = Convert::ToString(vola);
    
    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    Thanks Richard for the feedback, and no worries.

    Quote:http://www.cplusplus.com/reference/string/string/?kw=string[^]

    The string class is an instantiation of the basic_string class template that uses char (i.e., bytes) as its character type, with its default char_traits and allocator types (see basic_string for more info on the template).

    I will therefore work on your previous post and revert back to you tomorrow. Cheers

    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    might be a missing #include... as something is not logic here. as a matter of fact while typing any type double, float, char they are highlighted in blue therefore you could define any variable anywhere in the code based on those type. however while typing string, the latter does not seem to be recognized at all (not even highlighted). string is considered as plain text and thus unrecognized bizzare... Cheers

    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    Richard, Thanks for the advice. I will try it and let you know. Any idea why string type does not work from my side as opposed to your post? I am currently going it to see if people have encountered a similar issue. Best,

    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    alright.cheers.

    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    Cheers Richard. Please very quick question: do you know why the below code compiled but tirggered an error msg box

    Unable to cast object of type System.Data.DataColumn to type System.IConvertible

    lblvol->Text=System::Convert::ToString(sqrt(System::Convert::ToDouble(dbdataset->Columns["DataReturn"])));

    I was just aiming at computing the standard deviation of my return series held in ["DataReturn""]. can't see anything wrong as sqrt () is a built-in function from

    #include "math.h"

    Cheers

    C / C++ / MFC c++ database help tutorial question

  • c++ Windows Form app: How to grant public access to DataTable object?
    U User 11196121

    Hi All I am wondering if it's possible to create a DataTable object in one button handling event, and use it in another button handling event without getting error C2065: 'Datatable object' : undeclared identifier As a solution of last resort i've made an attempt (see below) which is unsuccessful.

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    //int row;
    DataTable^db=gcnew DataTable();
    Form1(void)

    Thx

    C / C++ / MFC c++ database help tutorial question

  • Perform operations on c++ DataTable
    U User 11196121

    Hi Richard, First and foremost, sincere apologies for a naivety mainly attributable to inexperience Yet. I acknowledge that the code posted is perfectly fine. While adapting to my needs, performing the loop before the below piece of code has resulted in blank "Ret" columns, confused me, and triggered some skepticism.

    sda->Fill(dbdataset);

    Now all look fine, and I'd like to thank you very much for your assistance. I spent the weekend on this mater whereas it took you barely few minutes from your side to bring a concrete solution. Hence I am indeed impressed, and hope to become a day a c++ pundit like you so as to give back by helping others on forums too.

    Cheers

    Member 11230372

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    Thanks again Richard. Could this suggestion be translated into codes for implementation? then I will surely learn from your post as this is much more concrete. cheers

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    Please Richard a quick look at my previous post (also copied below)

    "No, it still makes no sense. You add an extra column to your table and then you say you need to store information in extra rows. Choose one or the other."

    I've added an extra ret column
    DataColumn^rt_col=gcnew DataColumn();
    rt_col->ColumnName = "Ret";
    rt_col->DataType=System::Type::GetType("System.Double");
    dbdataset->Columns->Add(rt_col);
    Then I need to fill the rows of this new column "Ret" based on the values held in "Population" column.
    1st value of "Ret" should equal = log( 1st value of Population / 2nd value of Population)
    2nd value of "Ret" = log (3rd value of Population / 4th value of Population)
    ....

    ps: please let me reiterate that both "Ret" and "Population" are columns from the datable object dbdataset.

    Cheers

    ** in vba it will take me <3 minutes to perform it but I am stuck in c++ (part of the learning process I suppose ) Again thanks for the help

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    "No, it still makes no sense. You add an extra column to your table and then you say you need to store information in extra rows. Choose one or the other." I've added an extra ret column

    DataColumn^rt_col=gcnew DataColumn();
    rt_col->ColumnName = "Ret";
    rt_col->DataType=System::Type::GetType("System.Double");
    dbdataset->Columns->Add(rt_col);

    Then I need to fill the rows of this new column "Ret" based on the values held in "Population" column. 1st value of "Ret" should equal = log( 1st value of Population / 2nd value of Population) 2nd value of "Ret" = log (3rd value of Population / 4th value of Population) .... ps: please let me reiterate that both "Ret" and "Population" are columns from the datable object dbdataset. Cheers ** in vba it will take me <3 minutes to perform it but I am stuck in c++ (part of the learning process I suppose ) Again thanks for the help

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    Thanks for your proactivity Richard, which is really appreciated. after adding an extra column "Ret" my table is looking like: Ret |Population|ID|... Hence my purpose is to fill Ret rows with values from "Population" column for instance: Row["Ret"][0] = log (row["Population"][0] / row["Population"][1] ... hope it helps Cheers Member 11230372

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    :doh:

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    Hi Richard First of all thanks for the assistance. Basically what I am trying to achieve can be described as follows: 1-creating a database connexion, run a query and store the result in my Datatable's object dbdataset(see code below). city table has 5 columns 2-adding an extra column "ret" to dbdataset

    MySqlCommand^CmdDataBase = gcnew MySqlCommand("select * from world.city",conDataBase);
    try{
    conDataBase->Open();
    MySqlDataAdapter^sda= gcnew MySqlDataAdapter();
    sda->SelectCommand=CmdDataBase;
    DataTable^dbdataset=gcnew DataTable();
    DataColumn^rt_col=gcnew DataColumn();
    rt_col->ColumnName = "Ret";
    rt_col->DataType=System::Type::GetType("System.Double");
    dbdataset->Columns->Add(rt_col);

    3-fill "ret" rows based on values from column "Population"

    DataRow^rt_row;

                     for (int row=0;row<dbdataset->Rows->Count;row++)
                     {
                         rt\_row=dbdataset->NewRow();
                         rt\_row\["Ret"\]=log(System::Convert::ToDouble(rt\_row\["Population"\]\[row\])/System::Convert::ToDouble(rt\_row\["Population"\]\[row-1\]));
                         //rt\_row\["DataReturn"\]=System::Convert::ToDouble(dbdataset->Rows\[row\]\["Population"\])/System::Convert::ToDouble(dbdataset->Rows\[row-1\]\["Population"\]);
                         dbdataset->Rows->Add(rt\_row);
    

    1- and 2- are fine but I am completely stuck on 3. Hope you understand better my goal through this explanation. cheers member 11230372

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    Thanks Nareesh for the advice, although it does not help in solving the main issue: "Performing operations on DataTable" by referencing multiple columns Best, Member 11230372

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    Thanks Bryce for your prompt feedback. Look forward to getting Christian Grauss' assistance on this issue, after spending a few days to sort it out by myself. Cheers

    C / C++ / MFC c++ question

  • Perform operations on c++ DataTable
    U User 11196121

    Sure. Also posted i to "general programming" -> c/c++/mfc after realizing it. cheers

    C / C++ / MFC c++ question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups