참조하세요.
//=============================================================================
// Proxy_3_ByNameQuery
//=============================================================================
// Get a set of proxy objects using the ByName query.
// The Sample.Person ByName query uses the following SQL statement:
// SELECT ID, Name, DOB, SSN
// FROM Sample.Person
// WHERE (Name %STARTSWITH :name)
// ORDER BY Name
private void Proxy_3_ByNameQuery(string Name) {
WriteOutputHeader(Name);
try {
// Use the ByName() class method to create a CacheCommand.
CacheCommand Command = Sample.Person.ByName(CacheConnect);
CacheParameter Name_param = new CacheParameter("name", CacheDbType.NVarChar);
Name_param.Value = "A"; // Get all records where Name field starts with "A".
Command.Parameters.Add(Name_param);
Sample.Person person;
string ID;
// Create the datareader object and read the data stream.
CacheDataReader reader = Command.ExecuteReader();
while (reader.Read()) {
// get an ID and instantiate the corresponding object.
ID = reader[reader.GetOrdinal("ID")].ToString();
person = Sample.Person.OpenId(CacheConnect, ID);
Display.WriteLine(
person.Id() + "\t"
+ person.Name + "\n\t"
+ person.SSN + "\t"
+ person.DOB.ToString().Split(' ')[0].ToString()
);
};
// Clean up Reader and Command
reader.Close();
Command.Dispose();
}
catch (Exception err) {
WriteErrorMessage(Name, err);
}
} // end Proxy_3_ByNameQuery()
|