如何使用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