Click here to Skip to main content
15,884,388 members
Articles / Desktop Programming / MFC

MsAccess MdbTools with MFC and .NET

Rate me:
Please Sign up or sign in to vote.
4.82/5 (9 votes)
13 Jan 2012LGPL310 min read 68.9K   9.9K   49  
Viewer of MsAccess databases directly from MFC and .NET - Repair corrupt databases
// NETMdbTools.h

#pragma once

#include <map>
#include "../MdbToolsLib/MdbLibDatabase.h"
#include "../MdbToolsLib/MdbLibTable.h"

using namespace System;
using namespace System::Collections;

using namespace std;

namespace NETMdbTools
{
	public enum class NETMdbColType
	{
		NETMdb_BOOL = 0x01,
		NETMdb_BYTE = 0x02,
		NETMdb_INT = 0x03,
		NETMdb_LONGINT = 0x04,
		NETMdb_MONEY = 0x05,
		NETMdb_FLOAT = 0x06,
		NETMdb_DOUBLE = 0x07,
		NETMdb_DATETIME = 0x08,
		NETMdb_BINARY = 0x09,
		NETMdb_TEXT = 0x0a,
		NETMdb_OLE = 0x0b,
		NETMdb_MEMO = 0x0c,
		NETMdb_REPID = 0x0f,
		NETMdb_NUMERIC = 0x10
	};
	ref class NETMdbTable;

	public ref class NETMdbDatabase
	{
		public:
			NETMdbDatabase();
			~NETMdbDatabase();
			bool Open(String^ strfilename);
			void Close();
			void LoadTables();
			bool IsOpen() { return libdatabase->mdb != 0; }
						
			void MoveFirstTable();
			bool MoveNextTable();
			NETMdbTable^ GetTable();
			NETMdbTable^ GetTableByName(String^ strname);

		private:
			map<char*, CMdbLibTable, cmp_str>::iterator* itr;
			NETMdbTable^ table;
			CMdbLibDatabase* libdatabase;
	};

	ref class NETMdbColumn;
	ref class NETMdbValue;

	public ref class NETMdbTable
	{
		public:
			NETMdbTable();
			~NETMdbTable();
			void ClearTableColumns();
			void LoadTableColumns();

			bool CursorNextItem();
			void CursorMoveFirst();

			String^ Name;
			bool IsSystem;
			
			CMdbLibTable* table;
			void LoadFromLib();

			void MoveFirstCol();
			bool NextCol();
			NETMdbColumn^ GetCol();
			NETMdbColumn^ GetColByName(String^ strname);
			NETMdbValue^ GetValue(String^ strcolname);
		private:
			NETMdbColumn^ column;
			map<char*, CMdbLibColumn, cmp_str>::iterator* itr;
			NETMdbValue^ value;
	};
	public ref class NETMdbColumn
	{
		public:
			String^ Name;
			NETMdbColType GetType()  { return (NETMdbColType)column->Type; }
			int GetSize()
			{
				return column->Size;
			}
		
			CMdbLibColumn* column;
			void LoadFromLib()
			{
				Name = gcnew String(column->Name);
			}

			bool IsInt() { return column->IsInt(); }
			bool IsNumDec() { return column->IsNumDec(); }
			bool IsBinary() { return column->IsBinary(); }
			bool IsDate() { return column->IsDate(); }
	};
	public ref class NETMdbValue
	{
		public:
			String^ Value;

			int GetIntValue() { return value->GetIntValue(); }
			double GetDoubleValue() { return value->GetDoubleValue(); }
			DateTime^ GetTimeValue();
		
			CMdbLibValue* value;
			int GetLen() { return value->len; }
			void LoadFromLib()
			{
				Value = gcnew String(value->value);
				ptrvalue = (IntPtr)(value->value);
			}
			IntPtr ptrvalue;
	};
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
Argentina Argentina
System developer from Argentina.

Programmed in VB 5,6,.NET, C#, Java, PL-SQL, Transac-SQL, C, C++ and even some "calculator" language.

Love to build small, useful applications.
Usually building big and complicated apps based on solid, reliable components.

Hobbies: reading, photography, chess, paddle, running.

Comments and Discussions