如何在c ++中从DataTable引用列,循环行 [英] How do I reference columns, loop-in Rows, from DataTable in c++

查看:111
本文介绍了如何在c ++中从DataTable引用列,循环行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我可能会对下面的代码提出一些建议/修正,因为我还不熟悉在C ++中引用DataTable的多个列吗?困惑|困惑| :confused:您的投入将非常感激。在此先感谢。



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? Confused | Confused | :confused: 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"]);
					     //rt_row["DataReturn"]=System::Convert::ToDouble(dbdataset->Rows[row]["Population"])/System::Convert::ToDouble(dbdataset->Rows[row-1]["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);
		 }

推荐答案

请不要多重信息。你已经在C ++论坛上问了这个问题。
Please do not multipost. You already asked this in the C++ forum.


这篇关于如何在c ++中从DataTable引用列,循环行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆