josuetex / mikrotik4net

Automatically exported from code.google.com/p/mikrotik4net
Other
0 stars 0 forks source link

Support for ExecuteScalar (read single value) #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Will be implemented via IApiConnector - lowlevel API. 

Original issue reported on code.google.com by daniel.f...@gmail.com on 26 Jun 2011 at 3:34

GoogleCodeExporter commented 9 years ago
implemented in 0.9.2. See IApiConnector.ApiExecuteScalar method.

Original comment by daniel.f...@gmail.com on 23 Jul 2011 at 3:35

GoogleCodeExporter commented 9 years ago
Hello Daniel, I would like to know how to get a single value.
example:

Session = new TikSession TikSession (TikConnectorType.Api);

             session.Open ("192.168.1.2", "admin", "");
             IApiConnector apiConnector = (IApiConnector) session.Connector; //!!! MOST important row in sample
             / / execute scalar - select for single value
             apiConnector.ApiExecuteScalar string result = ("/ system / identity / print", new Dictionary <string, string> {{"name", ""}});
             Response.Write (result);

This example is used to take the number of people connected, but I'd like to 
take a single value, just the name of RB, as I do that?

Instead of count-only, tried to put name, but the wrong!

I await answers.

Original comment by helber...@gmail.com on 18 Jan 2012 at 2:23

GoogleCodeExporter commented 9 years ago
Hi,
  u should use ExecuteReader pattern when requesting "entity".

//execute reader without filter
//note: exactly one row is always returned in this case
var result = apiConnector.ApiExecuteReader("/system/identity/print");
Console.WriteLine(result[0].GetStringValueOrNull("name", true));

Original comment by daniel.f...@gmail.com on 18 Jan 2012 at 6:27