如何使用ClientID從Ilist中搜索客戶端名稱。我無法弄清楚。我創建了一個名爲clientdetails的簡單類,並與oracle數據庫建立了連接。現在我只想使用ClientID搜索列表並顯示結果。如何搜索Ilist中的項目並顯示輸出結果?
謝謝AK。
class ClientDetails
{
public string ClientID;
public string ClientName;
public string CreatedBy;
public string UpdatedBy;
public ClientDetails(string ClientID, string ClientName, string CreatedBy, string UpdatedBy)
{
this.ClientID = ClientID;
this.ClientName = ClientName;
this.CreatedBy = CreatedBy;
this.UpdatedBy = UpdatedBy;
}
}
class ConnectionSample
{
static void Main()
{
OracleConnection con = new OracleConnection();
//using connection string to connect to oracle database
IList<ClientDetails> myfield = new List<ClientDetails>();
try
{
con.ConnectionString = "xxxxxconnection stringxxxxx";
con.Open();
OracleCommand command = con.CreateCommand();
string abc = "SELECT * FROM CLI_CLIENT_900";
command.CommandText = abc;
OracleDataReader reader = command.ExecuteReader();
while (reader.Read())
{
myfield.Add(new ClientDetails(reader["CLIENT_ID"].ToString(), reader["CLIENT_NAME"].ToString(), reader["CREATED_BY"].ToString(), reader["UPDATED_BY"].ToString()));
}
}
catch (Exception ex)
{
Console.WriteLine("Error" + ex, "Error");
}
//close and dispose oracleconnection object
con.Close();
con.Dispose();
foreach (ClientDetails c1 in myfield.OrderByDescending(s => s.ClientID))
{
Console.Write("\n" + c1.ClientID);
Console.Write("\t"+c1.ClientName);
Console.Write("\t\t"+c1.UpdatedBy);
}
}
static void Display(IList<string> myfield)
{
foreach (string value in myfield)
{
Console.WriteLine("\t"+value);
}
}
爲什麼你不在*數據庫*中執行過濾?你真正的*問題*是什麼? – 2013-05-08 22:05:49
我想使用clientid在列表上執行搜索操作。 – AK1 2013-05-08 22:07:15
@AbeMiessler *因此*在這裏沒問題,如果OP的意思是「如何搜索一個項目並且_thereby_顯示它」 – poolie 2013-05-08 22:07:25