我有一个电子商务网络应用程序,它允许用户在我的网站上购买软件组件。我正在检索用户从SQL Server的UserTransactionHistory表中购买的发票号和软件组件标题。我将它们存储在ArrayList中具有的SoftwareTitles类asp.net/c#中的数据结构问题#
public class SoftwareTitles
{
string softwareTitle;
string invoiceNumber;
public SoftwareTitles(string softwareTitle, string invoiceNumber)
{
this.softwareTitle = softwareTitle;
this.invoiceNumber = invoiceNumber;
}
string InvoiceNumber
{
get
{
return this.invoiceNumber;
}
}
string SoftwareTitle
{
get
{
return this.softwareTitle;
}
}
}
}
的帮助和我加入这个类以这种方式数组列表。
ConnectionToSql con1 = new ConnectionToSql();
string connectionString = con1.ConnectionStringMethod();
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand cmd2 = new SqlCommand("SelectionOfSoftwareTitles", sqlConnection);
cmd2.CommandType = CommandType.StoredProcedure;
sqlConnection.Open();
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.HasRows)
{
while (dr2.Read())
{
String softwareTitle = (String)dr2[0];
String invoiceNumber = (String)dr2[1];
softwareTitlesArray.Add(new SoftwareTitles(softwareTitle, invoiceNumber));
int i = 0;
}
}
sqlConnection.Close();
dr2.Close();
但是,当我想检索与某个发票号码相关联的所有软件标题时。我无法做到。
我是否正确地做? ArrayList是否适合这种操作的数据结构?我应该怎么做?
@klabranche正如你可以看到它是一个多维数组列表。我想根据invoicenumber从该数组列表中检索值。 (int j = 0; j
2011-03-29 14:09:39