Uni Objects .NET Запуск запросов и получение результатов
Я играл с UniObjects .NET.
Я хотел бы иметь возможность выполнить запрос SELECT и получить данные в форме, где я могу пройти через данные.
Документация, которую я использовал, находится по адресу http://www.rocketsoftware.com/u2/products/universe/resources/technical-manuals/universe-v11r1/uonet-v11r1.pdf
В настоящее время я выполняю запрос, используя
// UniCommans is a new instance of the CreateUniCommand() method
UniCommand cmd = us1.CreateUniCommand();
string UVDatabaseName = "SLCUST";
// Command is the query that will be sent to the server to be rum
cmd.Command = "SELECT " + UVDatabaseName + " USING DICT " + UVDatabaseName + " WITH CUSREF PRICECODE";
Но я не знаю, как получить данные в один из объектов типов данных, которые они предоставляют:
- UniDynArray
- UniFile
UniSelectList
// OpenSession is used to open a new session to the database us1 = UniObjects.OpenSession("92.0.0.1", "username", "password", "/path/TOFILE", "uvcs"); // Create new instance a UniCommand UniCommand cmd = us1.CreateUniCommand(); string UVDatabaseName = "SLCUST"; // Command is the query that will be sent to the server to be run cmd.Command = "SELECT " + UVDatabaseName + " USING DICT " + UVDatabaseName + " WITH CUSREF PRICECODE"; // Buffer size for receiving data can be get/set using CommandBlockSize // 0 is unlimited, the full data set will be received cmd.CommandBlockSize = 0; // Execute() executes the Command on the server cmd.Execute(); // A status response is returned as a string in Response string response_str = cmd.Response; Console.WriteLine(response_str); // Check for the response of the UniCommand // UVS_COMPLETE = The command was completed, or unsuccessful if (cmd.CommandStatus == UniObjectsTokens.UVS_COMPLETE) { // How do I loop through the data set from my query? }
Я понял, что могу пройти через таблицу ВЕСЬ, используя следующий код:
// Create a Uni file, required for you can use a database file
UniFile custfile = us1.CreateUniFile("SLCUST");
// Create a select list from the ID returned from cmd.Response;
UniSelectList selectList = us1.CreateUniSelectList(0);
selectList.Select(custfile);
bool lLastRecord = selectList.LastRecordRead;
while (!lLastRecord)
{
string s = selectList.Next();
Console.WriteLine("Record ID:" + s);
lLastRecord = selectList.LastRecordRead;
}
Когда я запускаю команду, я получаю следующую строку ответа
4665 записей, выбранных для выбора списка № 0
Я просто пытался получить доступ к списку "0", но это как его вписать в правильный тип класса:
UniSelectList selectList = us1.CreateUniSelectList(0);
1 ответ
Вы приближаетесь. Команда "SELECT" по умолчанию сгенерирует список ключей в списке выбора 0. Так что вам просто нужно назначить объект UniSelectList для этого. Вы на самом деле не хотите смотреть на ответ команды, за исключением случаев, когда вы хотите проверить, не сгенерировала ли команда ошибку:
// OpenSession is used to open a new session to the database
us1 = UniObjects.OpenSession("92.0.0.1", "username", "password", "/path/TOFILE", "uvcs");
// Create new instance a UniCommand
UniCommand cmd = us1.CreateUniCommand();
string UVDatabaseName = "SLCUST";
// Command is the query that will be sent to the server to be run
cmd.Command = "SELECT " + UVDatabaseName + " USING DICT " + UVDatabaseName + " WITH CUSREF PRICECODE";
UniSelectList uSelect = uSession.selectList (0);
// Execute() executes the Command on the server
cmd.Execute();
while (!lLastRecord)
{
string s = uSelect.Next();
Console.WriteLine("Record ID:" + s);
lLastRecord = selectList.LastRecordRead;
}