Data retrieving from table

PoweRoyPoweRoy Member Posts: 43
edited 2006-03-06 in Navision Attain
i am trying to get some data out of records from a database
database is 3.6 and driver is 3.7
programmed this code in visual C# .net

what i accieved:
-connecting/disc to database
-open/close company
-listing of tables
-open/close tables
-listing of fields of a table

I am trying to get the data out of a record with GetFieldData()
htable and record are both handle's (int)
what i tried:

this one works partially, j is the size of the field and i retrieve that, only the var in the field i dont receive
//dll loader
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
		 private static extern int DBL_GetFieldData(string dst, int dstsize, int hTable, int record, int fieldnr);

//the parser
case "lr" : //list records
	int record = DBL_AllocRec(htable);
	DBL_InitRec(htable, record);
	string s = "temp string";
			
	if (DBL_FindRec(htable, record ,"-") )
	{
		int j = DBL_GetFieldData(s,100,htable, record,1);
		Console.WriteLine(Convert.ToString(j) + s);
		Console.WriteLine("findrec succes");

	}
	else result.Add("No records found"); 
	DBL_FreeRec(record);
	break;


also used
//the dll loading
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
		 private static extern int DBL_GetFieldData(char[]dst, int dstsize, int hTable, int record, int fieldnr);

//the parser
case "lr" : //list records
	int record = DBL_AllocRec(htable);
	DBL_InitRec(htable, record);
	char[] s = new char[100];
	
		
	if (DBL_FindRec(htable, record ,"-") )
	{
		int j = DBL_GetFieldData(s,100,htable, record,1);
		Console.WriteLine(Convert.ToString(j));

		string temp = "";
		for (int k = 0 ; k < 100 ; k++) 
		{
			temp = temp + s[k];
		}
		Console.WriteLine(temp);
		Console.WriteLine("findrec succes");
	}
	else result.Add("No records found"); 
	DBL_FreeRec(record);
	break;

also tried with both the examples to use the 1 param as a ref (ref string dst )

is i use the function DBL_GetFieldData(int hTable, int record, int fieldnr);
i get a NullReferenceException
with
DBL_GetFieldData(int hTable, int record, int fieldnr); i tried to receive a object cause in VB u receive a variant. no succes

Could anyone look at the code an give me a sollution for this prob that's bothering for couple of days :P

Comments

  • PoweRoyPoweRoy Member Posts: 43
    *bump*

    Noone knows a sollution?

    meanwhile i tried to start another project and try to connect with odbc only the .open isnt working :P suspect the connection string, but whats the valid one for navision?..
  • PoweRoyPoweRoy Member Posts: 43
    cause the first param is a void* i thought using a IntPtr could be helpfull but still i dont get any data:
    [DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
             private static extern int DBL_GetFieldData( IntPtr dst, int dstsize, int hTable, int record, int fieldnr);
    
    case "lr" : //list records
                        int record = DBL_AllocRec(htable);
                        //DBL_InitRec(htable, record); not needed only for changing and inserting a record
                        IntPtr s = new IntPtr();
                                
                        if (DBL_FindRec(htable, record ,"-") )
                        {
                            
                            int j = DBL_GetFieldData(s,100,htable, record,1);
                            Console.WriteLine(Convert.ToString(j)+Marshal.PtrToStringAnsi(s));
    
                            Console.WriteLine("findrec gelukt");
                        }; 
                        break;
    

    but it gives a "An unhandled exception of type 'System.NullReferenceException' occurred in csharptest.exe

    Additional information: Object reference not set to an instance of an object" error

    are there any other solutions?
  • PoweRoyPoweRoy Member Posts: 43
    due the conversion probs i found a program that convert a .h file to c# code. The program is called Pinvoke Wizard made by Paul Yao, but the problem is that it cant convert the typedefs :(

    is there another way to make the .h file usefull in c#?
Sign In or Register to comment.