I'm beginning to convert my Access 2007 module to C# so I can deploy it to my SQL Server. Just in step 1, retrieving the lists on the SP server. I had something like it working using VS2005, but things seem to have changed in VS2010. Here's my code...
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Timesheets
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CPAS_ListSVC.Lists listService = new CPAS_ListSVC.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
listService.Url = "http://moss.mava.xxxxxx.com/FACSEC/xxxfacilities/XXXCONSTRUCTION/CPAS/_vti_bin/lists.asmx"; // Site
System.Xml.XmlNode activeItemData = listService.GetListItems("","",null, null, "500", null, "");
tbXML.Text = activeItemData.ToString();
}
}
}
I'm getting an error when I instantiate the variable 'listService'. Compiler says ".lists" is not part of CPAS_ListSVC....
Indeed, Intellisense agrees (what a surprise....) Is there a different class I should be instantiating?
Found the answer:
I needed to use a Web Service instead of a standard service.
Related
I think this might be more generic, but in this case I try to create a c++ CLR to Microsoft Dynamic NAV.
If I do this in C# it works fine. C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VisualCSharp
{
public class MyTest
{
public MyTest()
{
}
public int AddTest(int a, int b)
{
return a + b;
}
}
}
When I try to add that to Dynamic NAV, I find it:
Select and press OK:
So far so good.
Then I like to do the same in C++ with a CLR class.
I start with creating a C++ CLR Class library and add the code for the test: (I did it inline here, just to keep code simple, but it does not matter if I separate it.)
#pragma once
using namespace System;
namespace VisualCPP
{
public ref class MyTest
{
public:
MyTest()
{
};
int AddTest(int a, int b)
{
return a + b;
};
};
}
Do the same with this. In Assembly list it come up identical to the VisualCSharp addin, but it shows up as Processor "x86", but thats ok. I have C# that also do that (COM wrappers) and they also work fine.
However, when I press "OK" i do get an error telling me that it can not load the type "VisualCPP".
So, question is: What am I missing? I know that the CLR code is different as it is not pure managed (even using the depricated /pure compile option does not work), but is there some kind of setting or declaration that had to be done to make my class visible?
As far is I know you cannot use unmanaged code in NAV.
You assembly also need to be signed - in you example the Public Key Token is null therefore it's not gonna work.
Situations like that I always recommend to create a wrapper dll to handle the unmanaged code though it (for example this is what Microsoft was done with the Office SDK)
I hope it helps.
Cheers!
I am trying to incorporate Aspose Cells for .NET into this class that is using Excel Interop (rather than rewrite the whole thing to use Aspose Cells, which I am just now trying out, I want to at least start with a hybrid approach).
The problem is that I get a "Type mismatch" exception with this code:
private Workbook _xlBook;
. . .
Worksheet asposePT = _xlBook.Worksheets[_xlBook.Worksheets.Add()];
My project has a reference to Aspose.Cells, version 16.11.0.0 (Runtime version v4.0.30319)
I have these usings in the class file:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using ReportRunner.SharedCode;
using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
This is the exception detail:
System.Runtime.InteropServices.COMException was caught
HResult=-2147352571
Message=Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
Source=System.Dynamic
ErrorCode=-2147352571
StackTrace:
at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String
message)
at CallSite.Target(Closure , CallSite , ComObject , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at CallSite.Target(Closure , CallSite , Sheets , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at ReportRunner.ProduceUsage.ProduceUsageRpt.PopulatePivotTableSheetAsposeCells() in c:\Projects\ReportRunner -
Private Build\ReportRunner\ProduceUsage\ProduceUsageRpt.cs:line 1550
at ReportRunner.ProduceUsage.ProduceUsageRpt.GenerateProduceUsageRpt() in c:\Projects\ReportRunner - Private Build
\ReportRunner\ProduceUsage\ProduceUsageRpt.cs:line 167
InnerException:
ProduceUsageRpt.cs:line 1550 is:
Worksheet asposePT = _xlBook.Worksheets[_xlBook.Worksheets.Add()];
Do I need a "using Aspose" or something like that? Do I need to explicitly declare Worksheet as an Aspose Worksheet (as opposed to Excel Interop), or what?
UPDATE
Even when I changed the code from this:
Worksheet asposePT = _xlBook.Worksheets[_xlBook.Worksheets.Add()];
asposePT.Name = "AsposePivotTable";
Aspose.Cells.Pivot.PivotTableCollection pivotTables = asposePT.PivotTables();
...to this (not parens are removed at end of last line):
Aspose.Cells.Worksheet asposePT = _xlBook.Worksheets[_xlBook.Worksheets.Add()];
asposePT.Name = "AsposePivotTable";
Aspose.Cells.Pivot.PivotTableCollection pivotTables = asposePT.PivotTables;
...I still get the same exception.
Well, Aspose.Cells APIs (an independent .NET library) and MS Excel Interop (Office Automation) APIs are different in many ways, both have different architectures, so you cannot just parse objects regarding their API b/w them. I think you should use only Aspose.Cells APIs to instantiate a Workbook (spreadsheet), add/update or manipulate data into the worksheets, etc. and finally save the Excel file. I guess your underlying _xlBook object might be culprit which you might have instantiated with respect to MS Excel Interop. APIs.
I am working as Support developer/ Evangelist at Aspose.
How do I make a connection between my C++ project and SQL Server 2008 ? Refering to some articles on the Internet, the best way is to use ADO.NET API. I've searched some samples of code making the crud operations and showing how to make a DB connection, and here is the best tutorial that I've found.
The issue here, after making a new project New > Visual C++ > Empty Project (.NET Framework 4.5) some errors occured when I've copyied/pasted the first snippet, which is :
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
// Standard
#using <mscorlib.dll>
#using <System.dll>
#using <system.data.dll> // This is required for the ADO.NET Provider
#include <tchar.h>
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
// This is the entry point for this application
int _tmain(void)
{
SqlConnection * mySQLConnection;
SqlCommand * mySQL;
SqlDataReader * myReader;
try
{
mySQLConnection = new SqlConnection(
S"server=local;Trusted_Connection=yes;database=pubs;");
mySQL = new SqlCommand (S"select * from authors",
mySQLConnection);
mySQLConnection->Open (); // Open up the connection
myReader = mySQL->ExecuteReader ();
while(myReader->Read ())
Console::WriteLine(myReader->get_Item("au_lname")->ToString ());
}
catch(Exception * e)
{
Console::Write(e->ToString () );
}
__finally
{
myReader->Close ();
mySQLConnection->Close();
}
return 0;
}
here is the first error of 22 :
2 IntelliSense: "#using" requires C++/CLI mode c:\Users\Nectarys\Documents\Visual Studio 2013\Projects\Project2\Project2\Source.cpp
How do I fix this, please ? (If the problem cames from the provider, how do I check if I have it installed and that I have the right version ?)
Note : I've included "stdafx.h" into my project. I haven't installed any provider after this copy/paste.
The error is because your project does not have the Common Language Runtime flag set, so it is trying to compile as native code instead of managed. To set the flag, right-click on the project and click on Properties, under the general section there is a "Common Language Runtime Support" option.
The tutorial you linked is from 2002 and uses manged C++, which was introduced before CLI/C++. To compile managed C++, the flag needs to be set to /clr:oldsyntax. Visual Studio intellisense will give you errors because it does not support managed C++, only CLI/C++. A migration guide is here: http://msdn.microsoft.com/en-us/library/ms235289.aspx, but essentially you need to replace the asterisks in your variable declarations with hats ("^"), use gcnew instead of new, do not put a "S" in front of strings (they're automatically managed strings in managed code), and change how you're accessing an item of the reader to use the array accesssor. The new code would be this (compile with /clr):
#using <mscorlib.dll>
#using <System.dll>
#using <system.data.dll> // This is required for the ADO.NET Provider
#include <tchar.h>
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
// This is the entry point for this application
int _tmain(void)
{
SqlConnection ^ mySQLConnection;
SqlCommand ^ mySQL;
SqlDataReader ^ myReader;
try
{
mySQLConnection = gcnew SqlConnection(
"server=local;Trusted_Connection=yes;database=pubs;");
mySQL = gcnew SqlCommand ("select * from authors",
mySQLConnection);
mySQLConnection->Open (); // Open up the connection
myReader = mySQL->ExecuteReader ();
while(myReader->Read ())
Console::WriteLine(myReader["au_lname"]->ToString ());
}
catch(Exception ^ e)
{
Console::Write(e->ToString () );
}
__finally
{
myReader->Close ();
mySQLConnection->Close();
}
return 0;
}
Unfortunately I do not know of a guide on how to use the SqlClient written in CLI/C++.
My company wants me to create a custom screen in solomon to load some data from a table in the database.
They said used visual studio .net and i see manuals it says use VBA.
What should I use? VBA or visual studio 5?
How do I create a new application?
We got similar request from our customer. We're using Dynamics Solomon 2011. After doing some research, we found that we will need to create a development environment by installing VS 2008 first and then install Solomon over it. Installing Solomon after VS will setup some project templates in Visual Studio for Solomon development.
https://community.dynamics.com/product/sl/f/35/t/80585.aspx
There is some talks also that VS 2010 is not recommended for use when developing for Dynamics Solomon.
I believe also that there is SDK for Dynamics Solomon that you can use inside you application to connect to Solomon database and use data objects. We didn't try this yet but we found some references talking about developing code using this SDK.
http://www.microsoftdynamicsforums.com/forums/forum_posts.asp?TID=191&title=solomon-Object-model-code
Below is a sample code that uses Solomon SDK:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Dynamics.SL.ObjectModel;
using System.Threading;
using System.Runtime.InteropServices;
namespace LoginSL
{
class Program
{
[DllImport("kernel32")]
static extern void Sleep(uint dwMilliseconds);
public static Microsoft.Dynamics.SL.ObjectModel.SIVToolbar sivTB;
public static Microsoft.Dynamics.SL.ObjectModel.SIVApplication sivApp;
static void Main(string[] args)
{
sivTB = new SIVToolbar();
sivTB.Login("servername", "systemdb", "company", "username", "password");
sivApp = sivTB.StartApplication("9850000.exe");
sivApp.Visible = true;
string datafile = "C:\\0101000.DTA";
string ctrlfile = "C:\\0101000.ctl";
string outfile = "C:\\0101000.log";
//In C# "\\" is the predefined escape sequence for backslash.
sivApp.Controls["cdata"].Value = (datafile.ToUpper());
sivApp.Controls["cfiletype"].Value = "ASCII";
sivApp.Controls["cscreen"].Value = "0101000";
sivApp.Controls["ccontrol"].Value = (ctrlfile.ToUpper());
sivApp.Controls["coutput"].Value = (outfile.ToUpper());
sivApp.Controls["cBegProcessing"].Value = true;
Sleep(5000); //remove the comment marks at the beginning of this line for workaround
sivApp.Quit();
sivApp.Dispose();
//GC.Collect();
//GC.WaitForPendingFinalizers();
//GC.Collect();
Sleep(5000); //remove the comment marks at the beginning of this line for workaround
sivTB.Logout();
sivTB.Quit();
sivTB.Dispose();
//GC.Collect();
//GC.WaitForPendingFinalizers();
//GC.Collect();
//MessageBox.Show("TI is complete"); // Displays complete message
}
}
}
I'm using jquery, ajax, & .net to call a method. I see lots of examples on the net saying to put [Webmethod] above the method but I'm keeping getting the error the type or namespace name 'webmethod' could not be found. I have put "using System.Web.Services;" at the top. What else needs to be done?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
}
Add a reference to System.Web.Services.dll in your project.
It is most likely missing for you to be getting this error because you already have the correct using statement
Add the following on top of the page:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
Simple answer to this question is to just Add reference of system.web.services from .net framework folder.
Example:
Consider I have a project which is already referenced system.web.services
Now If I right click on System.web.services
You can see that this assembly is inside .Net Path so you can easily add reference of this assembly in your project from there.
Solution
Just right click on references ,select add reference click browser button of selection manager window go to path and add references like this.