# VBForums CodeBank > CodeBank - C# >  N-Tier in C# (2.0)

## dee-u

This small app is a demo of N-Tier using C#. I haven't got a chance yet to do a full-pledge app in C# hence I played with this as a preparation for any impending projects I would tackle using C#.

The base class in DAL uses Factory Class to create a connection object base on the type of derived class, whether it is MS Access or SQL Server; reusabilty is what I have in mind when I decided to go on this design. The DAL also have support for transaction which can be triggered by method SetTransaction, CommitTransaction and RollbackTransaction. I have added in DAL the most common functions I use when dealing with database.

The BLL contains the Entity representation of an Employee and the CRUD operations. It also got an AuditLog where all CRUD operations will be logged in another database; when updating records all changed columns will also be logged. In BLL there is also stuff for Compacting, Repairing and backing-up Access database. Concurrency checking is also supported using the RowVersion method.

There are little thing that I did in the UI that may serve useful to 'newbies' out there like changing the color of the textbox in focus, moving to the next control when hitting the Enter key and moving to the previous control when hitting the Up key, etc... 

This also have an Exception Logger where any exceptions can be logged in the Event Log and in a text file.

So check this out! Any comments/criticisms/feedbacks will be highly appreciated. :-)

BTW, just place the two MS Access database in your C:\Drive...

----------


## r_amin

> This small app is a demo of N-Tier using C#. I haven't got a chance yet to do a full-pledge app in C# hence I played with this as a preparation for any impending projects I would tackle using C#.
> 
> The base class in DAL uses Factory Class to create a connection object base on the type of derived class, whether it is MS Access or SQL Server; reusabilty is what I have in mind when I decided to go on this design. The DAL also have support for transaction which can be triggered by method SetTransaction, CommitTransaction and RollbackTransaction. I have added in DAL the most common functions ..........................



Is it C Programming? I need Visual Basic.

----------


## Kasracer

> Is it C Programming? I need Visual Basic.


Since it's in the C# Codebank, the code would be in C# (it's also in his title).

You could always make a DLL with the C# code, compile it and then reference that in your VB application

----------


## dee-u

I made the ff. utility to create .cs files out of your Access database just how I did it in the program I cited above... I hope one way or another this my serve useful...  :Smilie:

----------


## dee-u

Newer version with improved architecture though it's not yet complete as I am still refining my pattern based on some feedbacks from friends out there...  _Kamusta mga kabayan!_

----------


## MrMM

Hi there,

Are you progressing on the N-tier thingy  :Wink:  ? I'm curious about that.

Greets

----------


## CodeMaker

Hi 
 Nice to know about your work. I need some connection help from you regarding your code. You have used MS Access. I would like to connect Oracle DataBase. In DataAccessType Class i can see SQL and MS Access. I would like to add Oracle here. I tried following Code


VB Code:
public class OracleServerDatabase : DataAccess.Methods
                    {
                     public OracleServerDatabase(string connectionString)
                          : base("Oracle Server", connectionString)
                     }

But i really do not know where i can set it ...

Please tell me how can i connect..






> Newer version with improved architecture though it's not yet complete as I am still refining my pattern based on some feedbacks from friends out there...  _Kamusta mga kabayan!_

----------


## MrSorceror

Dear Mr,

how if i want to select a list that contain a where clause (for ex: select * from employee where LastName like 'ABC'), i have tried, but still have an error (on parameter that given)..

thanks

regards

Andy

----------


## MrMM

Hi there,

What exactly is the problem then ?

Greets MM  :wave:

----------


## MrSorceror

here is my some problems:
          public static List<Entities.GUI.MenusProgram> LoadTab              (Entities.QueryGenerator query)
            query.SetTableName = "MenusProgram";
            query.AddWhereField(Entities.GUI.MenusProgram.MenusProgramField.MnuTab.ToString(), "H R D", Entities.QueryGenerator.Operand.Like);
            List<Entities.GUI.MenusProgram> MenusProgramCollection = _dataPortal.FetchMany(query.GetSelectSql(), query.WhereFields);
            return MenusProgramCollection;
        }

and caled by this code

            Entities.QueryGenerator query = new Entities.QueryGenerator();
            query.IncludeField(Entities.GUI.MenusProgram.MenusProgramField.MnuTab.ToString());
            query.AddOrderBy(Entities.GUI.MenusProgram.MenusProgramField.MnuTab.ToString(), "ASC");

            List<Entities.GUI.MenusProgram> MenusPrograms = BusinessLogic.GUI.MenusProgramManager.LoadTab(query);

i get a problem, when adding ...query.AddWhereField(Entities.GUI.MenusProgram.MenusProgramField.MnuTab.ToString(), "H R D", Entities.QueryGenerator.Operand.Like);

i just want to retrieve some records, but with some criteria, with Like, =, etc..

thanks,
regards 


andy

----------


## dee-u

What sort of problem are you encountering?

----------


## shakti5385

There is so much zip file Can I know What is the final ZIp File??

----------


## shadowcodes

hi dee u

thank you for the awsum sample..it was alot of help to me..

but i have a little question



```
protected Methods(string databaseType) : base(databaseType)
        {}
```

this above code..in your dataaccess.methods class.which creates a method whatever the databaseype which is specified when instantion of the object..

but sorry if im asking a crap..but why do you use that  *base(databaseType)* part in the inhretince part..is that  something like a generic type..just asking for clearifications..


is the above code and below are the same or is there anything special happening with the *base(databaseTYpe)*



```
protected Methods(string databaseType) : base
        {}
```


thanx in advance..sorry if im asking a bad question as im a begginer..to c#..im just analaysing your code.. :Blush:

----------


## smhaig

where is the C:\dee_u.mdb  access file for this sample

thanks

----------


## iPrank

> where is the C:\dee_u.mdb  access file for this sample
> 
> thanks


Read the very last sentence of the first post and get the first attatchment.  :Smilie: 

BTW, welcome to VBForums !  :wave:

----------


## shadowcodes

im getting the following error when i try to update a  record



```
System.InvalidCastException was unhandled
  Message="Specified cast is not valid."
  Source="BusinessLogic"
  StackTrace:
       at BusinessLogic.AuditLog.WriteAudit(String affectedTable, String moduleName, String action, String reason, String code, Int32 rowVersion, Employee newEmp, Employee oldEmp) in C:\Users\Aneef\Desktop\stuff\EmployeeRecordsearlyedition\EmployeeRecords\BusinessLogic\BusinessLogic\AuditLog.cs:line 37
       at BusinessLogic.EmployeeCRUD.UpdateRecord(Employee newEmp, Employee oldEmp) in C:\Users\Aneef\Desktop\stuff\EmployeeRecordsearlyedition\EmployeeRecords\BusinessLogic\BusinessLogic\EmployeeCRUD.cs:line 179
       at ApplicationLayer.frmEmployee.toolStripSave_Click(Object sender, EventArgs e) in C:\Users\Aneef\Desktop\stuff\EmployeeRecordsearlyedition\EmployeeRecords\ApplicationLayer\ApplicationLayer\frmEmployee.cs:line 480
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ToolStrip.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ApplicationLayer.Program.Main() in C:\Users\Aneef\Desktop\stuff\EmployeeRecordsearlyedition\EmployeeRecords\ApplicationLayer\ApplicationLayer\Program.cs:line 39
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
```

what is the resolution for this helpppp

----------


## dee-u

This past days I have got time to tinker with the code and here it is...

New Features:
-added inserting images, both from using camera and loading selected picture
-can now connect both to MS Access and SQL Server 2000
-can now utilize queries/stored procedures to add/edit/delete records
-integrated with a simple login menu and splash screen
-improved architecture
-bug fixes

----------


## iondollinger

Is there any chance to post here a zip with the last source code?

----------

