Hi
I have below code but i am getting above error on CreateConnection();
static class Program
{
public static SAPbouiCOM.Application oApplication = null;
public static SAPbobsCOM.Company oCompany = null;
[STAThread]
static void Main(string[] args)
{
try
{
CreateConnection();
Menu oMenuItems = null;
oMenuItems = new Menu();
// Start Message Loop
System.Windows.Forms.Application.Run();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
Thanks
Amit MohantyPosted Apr 19, 2024, 6:10 AM
This error occurs when trying to access an instance member from a static context. I think CreateConnection() is likely an instance method, and you're trying to call it from a static context in your Main method. If possible, make the CreateConnection() method to be static if it doesn't rely on instance-specific data. For example:
Otherwise you'll need to create an instance of the class it belongs to and then call the method on that instance. For example: