How do I use ICalculator in ArcEngine? - esri-arc-engine

I'm trying to calculate value for field from the attribute table of a shapefile using ArcEngine, looking up in EDN & ArcGIS help and I wrote code as below:
ICalculator pCalculator = new Calculator();
pCalculator.Field = pField.Name;
string ex = "!POP06!-!POP02!";
pCalculator.Expression = ex;
pCalculator.Calculate();
pField is the target field I want to update the value, POP06 & POP02 are two fields I use to calculate, using ! for python.
When I run the program VS2010 said "Error HRESULT E_FAIL has been returned from a call to a COM component". I could tell that ICalcultor haven't set any dependence on attribute table, but I don't know how to do. Also, are there any other problems in my code?

Related

Return multiple records from subroutine and parse into datatable [Unidata][U2.NET]

I am working with Unidata, and ADO.NET using the U2 .NET Provider. This may be a shot in the dark as there are not many resources for Unidata and .NET these days.
Currently I can only return a single MV record 153926þIþ and parse it using MV_To_DataTable. I'd like to return multiple records like 153926þIþÿ153926þIþÿ. Is there any built in mechanism for doing this? I fear I will have to write the extension to best accomodate me.
I retrieve a single record in a unidata subroutine this way:
SUBROUTINE GETITEMS(results)
EXECUTESQL "SELECT ID, STATUS, DESC FROM ITEMS TO GETITEM_LIST;"
DONE = 0
RECCNT = 0
LOOP
RECCNT += 1
READNEXTTUPLE REC FROM "GETITEM_LIST" ELSE DONE = 1
results := REC
IF RECCNT EQ 1 THEN EXIT
UNTIL DONE
REPEAT
results
CLEARSQL
RETURN
Simple subroutine that returns one record without any record marks. This works when I use the U2Parameter method called MV_To_DataTable to parse it into an existing datatable.
However when I change the subroutine line:
results:= REC to results:= REC : #RM to append the record marks and remove the limit of 1, the MV_To_DataTable no longer is able to parse it correctly. In fact it will throw System.IndexOutOfRangeException: Cannot find column 3.
VB.NET Code:
' ... Open database connection called U2Connection ...
Dim cmd = U2Connection.CreateCommand
cmd.CommandText = "CALL GETITEMS(?)"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Clear()
cmd.Parameters.Add(New U2Parameter("#arg1", "") With {.Direction = ParameterDirection.InputOutput})
cmd.ExecuteNonQuery()
Dim tb As New DataTable
tb.Columns.Add("ID")
tb.Columns.Add("STATUS")
tb.Columns.Add("DESC")
cmd.Parameters.Item(0).MV_To_DataTable(tb) ' Error happens here
' System.IndexOutOfRangeException: Cannot find column 3.
It appears the method does not separate records. I could be interpretting this incorrectly.
*****UPDATE 2/9/2019
I went ahead and wrote my own extension method to support my return format with the record markers. It populates a datatable with records allowing me to continue as I normally would.
You are kind of straddling the Multivalue/System.Data divide here. If you have not already done so, I would suggest looking into the U2 Toolkit for .NET, which I believe is generally readily available if you are current on maintenance. It comes with some samples of how to do things like this in C# and VB as well some Entity Framework stuff.
But as to what is going on here, You are trying to put a U2Type.DynArray into a System.DataTable is kind of tricky as the DynArray is a Record state, which could contain multiple rows from multiple tables within a DataSet. As #RM is the terminator for a record so it turns DynArray into DynArray[] and you can't have that as a parameter as such.
To fix this with the minimum refactoring, you can still use MV_To_DataTable, but note that it is expecting your data to be tabular and in in a single record. These example assume a newline is an Attribute mark (#FM/#AM)
Here is the contents of what you are returning
Row1Column1
Row1Column2
Row1Column3:#RM
Row2Column1
Row2Column2
Row2Column3:#RM
Row13olumn1
Row13olumn2
Row13olumn3:#RM
And here is what MV_To_DataTable expects
Row1Column1:#VM:Row1Column2:#VM:Row1Column3
Row2Column1:#VM:Row2Column2:#VM:Row2Column3
Row3Column1:#VM:Row3Column2:#VM:Row3Column3
If you adjust your U2 sub to output that, it should work.
Additionally, you could try using your SQL command directly for .net, but that becomes perilous for other reasons depending on your data.
Good Luck!

Using contains on an integer in LINQ to SQL

I'm trying the following query:
Return _context.companies _
.Where(Function(c) c.id.StartsWith(filterCompanyId)) _
.ToList()
but because id is an integer, it doesn't work. I found this answer which suggests I can use
c.id.ToString().StartsWith ...
but that gives me the following error:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
When trying to use
.Where(Function(c) SqlFunctions.StringConvert(CDbl(c.id)).StartsWith("1"))
it doesn't work.
Any tips?
The relevant part is hidden in the error message:
'SqlFunctions' is not declared. It may be inaccessible due to its protection level
SqlFunctions is in the System.Data.Objects.SqlClient namespace (you can discover this by going to the "SqlFunctions Class" MSDN page and then checking the "Namespace:" entry). Thus, you need to import that namespace at the top of your code file:
Imports System.Data.Objects.SqlClient
Per #Heinzi's comment, StringConvert is not supported by the MySQL-EF-Provider. I ended up going with a query string:
Dim isExpiredInt As Integer = If(isExpired, 1, 0)
Dim query As String = "Select * FROM company WHERE (expired = 0 OR expired = {0}) AND name like {1} AND id like {2}"
Dim companies = _context.ExecuteStoreQuery(Of company)(
query,
"companies",
System.Data.Objects.MergeOption.AppendOnly,
isExpiredInt, "%" & filterCompanyName & "%", filterCompanyId & "%"
).ToList()
Return companies
Note the System.Data.Objects.MergeOption.AppendOnly is something I added so the objects from this query would be attached to my context (i.e. calling SaveChanges on this context would write to the database).
Hope that helps!

Sap Code Inspector - Generating a table of all PCodes linked to the classes

I have problems to read the error codes and corresponding messages of SCI message classes.
Is there an way to easy access those?
I'm using "Praxishandbuch SAP Code Inspector" as a reference, but in that regard it is of no help.
I looked in Se11 but the information to the messages isn't helpful.
Has someone an approch to build such a table?
You can try this, perhaps it will work for you. I use the code below to get the access to all the errors found by Code Inspector for particular user(s):
data: ref_inspec_a type ref to cl_ci_inspection.
ref_inspec_a = cl_ci_inspection=>get_ref(
p_user = pa_iuser
p_name = pa_inam
p_vers = pa_ivers ).
data: ls_resp type scir_resp,
lt_resp type scit_resp.
clear: ls_resp, lt_resp.
ls_resp-sign = 'I'.
ls_resp-option = 'EQ'.
ls_resp-low = pa_fuser.
insert ls_resp into table lt_resp.
call method ref_inspec_a->get_results
exporting
p_responsibl = lt_resp
exceptions
insp_not_yet_executed = 1
overflow = 2
others = 3.
Playing around with LT_RESP you can get results for more users at the same time.
After you execute the code above, you can check the attributes SCIRESTPS and SCIRESTHD of the object REF_INSPEC_A. These are the large tables, which contain the result data of the SCI check. You can either work with them on your own, or you can simply pass the object REF_INSPEC_A into the function module SCI_SHOW_RESULTS to get regular SCI user interface.
I found out that you can get all the changeable messages (found in SCI GoTo/Management Of/ Message Priorities) can be read from the scimessages attribute of the test classes.
With this help you can get about 60% of all errors.

Create a Crystal Report with dynamic tables at runtime

Hello I'm planning an application that is basically a reporting front-end for a database (proprietary Pervasive SQL) using an ODBC dsn-less connection string.
I am able to create the dataset in Visual Studio and link up the report(s) to the app. However in real world usage, the location of the database will be different per user. That is not the main problem. I overcame that with the connection string that allows you to set the location of the database path.
Here's the kicker...
The name of the tables that I want to read from are prefixed with a unique filename (actually the same name I mentioned above). I need crystal to re-map the table names at runtime. Just the table name prefixes really. The fields and names of the fields will not change.
Any ideas on where I should look for writing this block? I am using VS2010 & C# if that helps. I think thee should be some sort of class files that come with Crystal that can do some runtime reflection to get/set the table names?
Any thoughts would be welcome and appreciated.
Rob
Edit: I found some documents link that has API docs and other support. I will be studying them. They are all .chm files (Windows help files) so there is no "online" docs to search for.
Add a Crystal reportViewer change the name to objReport
add a public function ShowReport()
public void ShowReport(ReportDocument objReport)
{
Cursor.Current = Cursors.WaitCursor;
objReport.SetDatabaseLogon("", "dbpassword");
cRep.ReportSource = objReport;
this.Show();
Cursor.Current = Cursors.Default;
}
And Call it from anywhere in your application
ds = GetDataInDataSet();//fILL DataSet with your data
rptPSummary objRpt = new rptPSummary();
objRpt.SummaryInfo.ReportComments = "Have a nice day";
objRpt.SummaryInfo.ReportTitle = "Purchase Summary Report from " + sDate.ToString("dd/MM/yyyy") + " to " + eDate.ToString("dd/MM/yyyy");
objRpt.SetDataSource(ds);
frmReportView frmRpt = new frmReportView();
frmRpt.Text = objRpt.SummaryInfo.ReportTitle;
frmRpt.MdiParent = this;
frmRpt.ShowReport(objRpt);

Nhibernate.Search, Lucene, and the Criteria API: types mismatch

Update
I've been looking around the NHibernate.Search.Tests project to find out how the Criteria API is used (i find it immensely useful to look around the test code to have working examples) and i noticed that the way to use the Fulltext search is radically different. Here are two tests, one with the criteria API, one with the classic query schema:
[Test]
public void ResultSize()
{
IFullTextSession s = Search.CreateFullTextSession(OpenSession());
ITransaction tx = s.BeginTransaction();
// snipped the objects creation
QueryParser parser = new QueryParser("title", new StopAnalyzer());
Lucene.Net.Search.Query query = parser.Parse("Summary:noword");
IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
Assert.AreEqual(0, hibQuery.ResultSize);
// snipped the end of the test
}
[Test]
public void UsingCriteriaApi()
{
IFullTextSession s = Search.CreateFullTextSession(OpenSession());
ITransaction tx = s.BeginTransaction();
// snipped creation
IList list = s.CreateCriteria(typeof(Clock))
.Add(SearchRestrictions.Query("Brand:seiko"))
.List();
Assert.AreEqual(1, list.Count, "should get result back from query");
// snipped deletion
}
The second solution works under vb.net, at the cost of the useful Lucene query (which embarks it's own total of the corresponding rows) and at the cost of the Lucene ordering (or i couldn't find it)
Hello everyone,
yet again, i'm stumped on the path, but this time, i suspect something a bit more sinister than my usual erratic errors (cue ominous music)
I'm trying to combine FullText search using Lucene.net with paging and the Criteria API.
So far paging and the Fulltext search have been working flawlessly. Recently though, we had to use the criteria API to add specific filters to the query. So what i did was the following:
Create the Nhibernate.Search query object using the following
Private Function GetQuery(ByVal QueryString As String, ByVal Orders() As String) As IFullTextQuery
Dim ifts As IFullTextSession = Search.CreateFullTextSession(UnitOfWork.CurrentSession)
Dim analyzer As New SimpleAnalyzer
Dim parser As New MultiFieldQueryParser(SearchPropertyNames, analyzer)
Dim queryObj As Lucene.Net.Search.Query = parser.Parse(QueryString)
Dim nhsQuery As IFullTextQuery = ifts.CreateFullTextQuery(queryObj, New System.Type() {GetType(T)})
For i As Integer = 0 To Orders.Count - 1
Orders(i) = Orders(i) & "FS"
Next
nhsQuery.SetSort(New Sort(Orders))
then add my Criteria to the query:
Dim crit As ICriteria = ifts.CreateCriteria(GetType(T))
Dim criterion As ICriterion
If criteria IsNot Nothing Then
For Each criterion In criteria
If (Not criterion Is Nothing) Then
crit.Add(criterion)
End If
Next
End If
nhsQuery.SetCriteriaQuery(crit)
but when i list the resulting query, i receive the following exception
Criteria query entity should match query entity
A quick glance in the FullTextQueryImpl source file (method GetLoader) shows that there is a comparison between the type name given to the NHibernate.Search query object and the EntityOrClassName property for the Criteria object. That's where my problems appear because the FullTextQueryImpl uses the Name, and the Criteria uses the Fullname. Here's a constructor code for the CriteriaImpl class
Public Sub New(ByVal persistentClass As Type, ByVal session As ISessionImplementor)
Me.New(persistentClass.FullName, CriteriaSpecification.RootAlias, session)
Me.persistentClass = persistentClass
End Sub
and here's the comparison:
Dim entityOrClassName As String = DirectCast(Me.criteria, CriteriaImpl).EntityOrClassName
If ((Me.classes.GetLength(0) = 1) AndAlso (Me.classes(0).Name <> entityOrClassName)) Then
Throw New SearchException("Criteria query entity should match query entity")
End If
As a result, the comparison fails and the exception is thrown. I tried playing around with the aliases to no avail since the comparison is not using the aliases.
Am i missing something huge in my mix of the Fulltext search and the Criteria API, or is it something else? Does it work as expected in C#, because i'm having a weird feeling that it could be vb.net related?
Thank you for reading,
Samy
Looks like this has been resolved with revision 1611 of NHibernate.Search :
Revision: 1611
Message: Fixed a bug where a full class name was being compared against a partial one. This was causing LuceneQueryTest.UsingCriteriaApi to fail.
Modified : /trunk/src/NHibernate.Search/src/NHibernate.Search/Query/FullTextQueryImpl.cs
svn : https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Search/