如何使用 ClientID 从 Ilist 中搜索客户端名称。我无法弄清楚。我创建了一个名为 clientdetails 的简单类,并与 oracle 数据库建立了连接。现在我只想使用 ClientID 搜索列表并显示结果。
谢谢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);
}
}