更新时间:2022-01-06 22:15:04
开发人员融合 [ ^ ]自动翻译了它(一旦我在Nodes.Clear之后立即更正了评论)
Developer fusion[^] auto translated it (once I had corrected the comment immediately after the Nodes.Clear)
DataSet DSNWind = null;
System.Data.SqlClient.SqlConnection CNnwind = new System.Data.SqlClient.SqlConnection("DATA SOURCE=Server;USER ID=sa;INITIAL CATALOG=northwind;");
//<==== CHANGE HERE
System.Data.SqlClient.SqlDataAdapter DACustomers = new System.Data.SqlClient.SqlDataAdapter("SELECT CustomerID, CompanyName, ContactName, Country FROM customers WHERE country = 'Germany'", CNnwind);
System.Data.SqlClient.SqlDataAdapter DAOrders = new System.Data.SqlClient.SqlDataAdapter("SELECT CustomerID, OrderID, OrderDate, ShippedDate, ShipVia, Freight FROM orders where customerid in (select customerid from customers where country = 'Germany')", CNnwind);
System.Data.SqlClient.SqlDataAdapter DAOrderDetails = new System.Data.SqlClient.SqlDataAdapter("Select * from [Order Details] where OrderID in (SELECT OrderID FROM orders where customerid in (select customerid from customers where country = 'Germany'))", CNnwind);
DSNWind = new DataSet();
CNnwind.Open();
DACustomers.Fill(DSNWind, "dtCustomers");
DAOrders.Fill(DSNWind, "dtOrders");
DAOrderDetails.Fill(DSNWind, "dtOrderDetails");
//Close the connection to the data store; free up the resources
CNnwind.Close();
//Create a data relation object to facilitate the relationship between the Customers and Orders data tables.
DSNWind.Relations.Add("CustToOrd", DSNWind.Tables["dtCustomers"].Columns["CustomerID"], DSNWind.Tables["dtOrders"].Columns["CustomerID"]);
DSNWind.Relations.Add("OrdToDet", DSNWind.Tables["dtOrders"].Columns["OrderID"], DSNWind.Tables["dtOrderdetails"].Columns["OrderID"]);
///''''''''''''''''''''
TreeView1.Nodes.Clear();
////Dim i, n As Integer
DataRow parentrow = null;
DataTable ParentTable = null;
ParentTable = DSNWind.Tables["dtCustomers"];
foreach (DataRow parentrow_loopVariable in ParentTable.Rows) {
parentrow = parentrow_loopVariable;
TreeNode parentnode = default(TreeNode);
parentnode = new TreeNode(parentrow[0]);
TreeView1.Nodes.Add(parentnode);
///'populate child'''''
///''''''''''''''''''''
DataRow childrow = null;
TreeNode childnode = default(TreeNode);
childnode = new TreeNode();
foreach (DataRow childrow_loopVariable in parentrow.GetChildRows("CustToOrd")) {
childrow = childrow_loopVariable;
childnode = parentnode.Nodes.Add(childrow[0] + " " + childrow[1] + " " + childrow[2]);
childnode.Tag = childrow["OrderID"];
///'populate child2''''
///'''''''''''''''''''''''
DataRow childrow2 = null;
TreeNode childnode2 = default(TreeNode);
childnode2 = new TreeNode();
foreach (DataRow childrow2_loopVariable in childrow.GetChildRows("OrdToDet")) {
childrow2 = childrow2_loopVariable;
childnode2 = childnode.Nodes.Add(childrow2[0]);
}
///'''''''''''''''''''''
}
///''''''''''''
}
它显示一条错误消息无法从对象"转换为字符串".
It is showing an error message "Cannot convert from ''object'' to ''string''.
.NET代码转换-转换代码 [