---矩型数组的应用---
我才开始学C#的时候对于矩型数数用起来会很迷惑,下面给个实例就会对它的认识有了一很好的了解!自己也 mark 一下~~`
public string[][] GetPortfolioIDAndRunID(string accountname)
{
OleDbConnection conn = new OleDbConnection(_oledbConnectionString);
conn.Open();
string sql = "select b.PortfolioID,b.RunID from Portfolios a left join Transactions b on a.PortfolioID = b.PortfolioID where "
+ "a.AccountName = '" + accountname +"' and b.RunID is not null group by b.PortfolioID,b.RunID order by b.RunID";
OleDbDataAdapter oledbDataAdapter = new OleDbDataAdapter(sql, conn);
DataTable dataTable = new DataTable();
oledbDataAdapter.Fill(dataTable);
string[][] strID = null;
if (dataTable.Rows.Count > 0)
{
strID = new string[dataTable.Rows.Count][];
for (int i = 0; i < dataTable.Rows.Count; i++)
{
DataRow dataRow = dataTable.Rows[i];
strID[i] = new string[2];
if (dataRow["PortfolioID"] != System.DBNull.Value)
{
strID[i][0] = dataRow["PortfolioID"].ToString();
}
if (dataRow["RunID"] != System.DBNull.Value)
{
strID[i][1] = dataRow["RunID"].ToString();
}
}
}
dataTable.Clear();
dataTable.Dispose();
conn.Close();
conn.Dispose();
return strID;
}
{
OleDbConnection conn = new OleDbConnection(_oledbConnectionString);
conn.Open();
string sql = "select b.PortfolioID,b.RunID from Portfolios a left join Transactions b on a.PortfolioID = b.PortfolioID where "
+ "a.AccountName = '" + accountname +"' and b.RunID is not null group by b.PortfolioID,b.RunID order by b.RunID";
OleDbDataAdapter oledbDataAdapter = new OleDbDataAdapter(sql, conn);
DataTable dataTable = new DataTable();
oledbDataAdapter.Fill(dataTable);
string[][] strID = null;
if (dataTable.Rows.Count > 0)
{
strID = new string[dataTable.Rows.Count][];
for (int i = 0; i < dataTable.Rows.Count; i++)
{
DataRow dataRow = dataTable.Rows[i];
strID[i] = new string[2];
if (dataRow["PortfolioID"] != System.DBNull.Value)
{
strID[i][0] = dataRow["PortfolioID"].ToString();
}
if (dataRow["RunID"] != System.DBNull.Value)
{
strID[i][1] = dataRow["RunID"].ToString();
}
}
}
dataTable.Clear();
dataTable.Dispose();
conn.Close();
conn.Dispose();
return strID;
}
---------------------------------------------------------------------------
He works his work in mysterious way!
He works his work in mysterious way!