|
Member 11230372 wrote: it looks like a different story when dealing with c++/cli Many things are different if you use C++/CLI, it is not something I have worked with, as C# is so much more intuitive, even though my background is mainly C++.
Member 11230372 wrote: Error C2440: 'initializing' : cannot convert from 'System::Data::DataColumn ^' to 'double' Of course you cannot convert a DataColumn to a double , they are totally different things; remember a column is a collection of cells not a single item. You can hold a double value in a DataColumn 's cell, but you need to access that with both the row and column indices.
|
|
|
|
|
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);
|
|
|
|
|
Sorry, I only ever spent a year doing advanced maths, and that was more than 50 years ago.
|
|
|
|
|
No worries Richard, and please note that I do thank you for your overall support.
Cheers
|
|
|
|
|
Hi all
I have a problem to formatted an int to the special format
example :
Int exp_int = 5640100;
a need writes the integer to 5 640 100
|
|
|
|
|
I'll tell you what you should do... but not how (you can look that up).
0.Load your integer to a string.
1.Every third character (right to left), insert a space.
2.Finish parsing loop when you have less than or equal to three characters left.
|
|
|
|
|
Have you looked at the GetNumberFormat() function? You can format numbers based on a specific locale, or a custom format (e.g., using a space as the thousand separator).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
C has a powerful printf[^] function to format variables...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Hi all
might I ask some advice/fixes on the below code, as I am still not familiar with referencing multiple columns from DataTable in c++ yet? Your inputs would be much appreciated. Thanks in advance.
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);
DataRow^rt_row;
for (int row=0;dbdataset->Rows->Count;row++)
{
rt_row=dbdataset->NewRow();
rt_row["Ret"]=System::Convert::ToDouble(rt_row["Population"])/System::Convert::ToDouble(rt_row["Population"]);
dbdataset->Rows->Add(rt_row);
}
sda->Fill(dbdataset);
BindingSource^bSource=gcnew BindingSource();
bSource->DataSource=dbdataset;
dtGrid->DataSource=bSource;
}
catch(Exception^ex) {
MessageBox::Show(ex->Message);
}
modified 23-Nov-14 20:38pm.
|
|
|
|
|
|
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.
|
|
|
|