|
|
Sure. Also posted i to "general programming" -> c/c++/mfc after realizing it. cheers
|
|
|
|
|
yeah so the man you want to ask is Christan Grauss, hes the man on exactly this sort of thing.
A lovely chap who is so helpful and nice too boot, he'd be more than happy to help you out
cheers
Bryce
MCAD
---
|
|
|
|
|
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
|
|
|
|
|
You missed :Evilgrinse: :Evilgrinse: :Evilgrinse: in your post
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
and give the game away?
MCAD
---
|
|
|
|
|
That would be only if the OP gets it :evilgrinse:
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
|
Don't take it personal, just Offtopic jokes
Without this "irony discharge" we would drive nuts
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
change
for (int row=0;dbdataset->Rows->Count;row++)
to
for (int row=0;row < dbdataset->Rows->Count;row++)
Due to in mathematics the commutative property, since row = 0, 0 = row, therefore can be written more interpretative as to reduce the cycle CPU
for (int row=0;0 < dbdataset->Rows->Count;row++)
|
|
|
|
|
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
|
|
|
|
|
Perhaps if you explained what the problem is then we would be able to offer some suggestions. Apart from the obvious error in the line:
for (int row=0;dbdataset->Rows->Count;row++)
which, presumably, is meant to be:
for (int row=0; row < dbdataset->Rows->Count; row++)
|
|
|
|
|
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]));
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
|
|
|
|
|
Member 11230372 wrote: 2-adding an extra column "ret" to dbdataset
Member 11230372 wrote: 3-fill "ret" rows based on values from column "Population"
Now I am confused, do you mean rows or columns? Assuming you mean columns, which is what you have added, your code should be something like:
for (int row=0; row < dbdataset->Rows->Count; row++)
{
rt_row=dbdataset->Rows[row];
rt_row["Ret"] = log(System::Convert::ToDouble(rt_row["Population"]) / --> not sure what this calculation should be
}
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
"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
modified 24-Nov-14 6:57am.
|
|
|
|
|
I showed you how to fill it in my previous answer, but I do not know what it is that you want to fill it with.
|
|
|
|
|
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
|
|
|
|
|
And once again, I repeat, I have already shown you how to fill these columns. You just iterate through the rows of your datatable inserting the values (however you calculate them) into the Ret column of each row.
|
|
|
|
|
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
|
|
|
|
|
|
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);<pre>
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
|
|
|
|
|
Hey guys, I'm learning c++ and I've got a question,
I have a class called <<test (name,="" id)="">>
and I want to store a list of the objects in another class called <<testlist>>
How can I do it properly?
Thanx
|
|
|
|
|