-
November 16th, 2009, 11:18 AM
#1
3-tier windows application
Hi all,
I have a requirement to create a GUI application using SQL Server 2005 as its backend. The database has some 15 tables and there are relationships among them. The UI would be a tabbed UI with about 6-7 screens and multiple controls on them. Although, the requirement does not state so, I want to create an 3-Tier application with Data Access Layer connecting to the database directly and calling the Stored procs and executing the queries. The next layer is the Business Logic layer, consisting of Objects to interact with the typed data sets in the DAL. The final layer is the UI with respective code behinds. I had a sample doing the same in ASP.NET, which I lost during some drive formatting. I want to replicate the same functionality, in winforms. The example, I did lose would have solved my purpose, but I think, it was from one of the EBooks, I read and I do not remember that anymore.
So it would be great if someone here provides me a 3-tier application as stated or points to a tutorial that does the same. I have seen the windows forms videos and samples; but for .NET 3.5, they have a demo using WCF, which I cannot use right now. I want it using ADO.NET classes only. Also, my requirement is using typed data set and shared functions in it calling stored procs. Anything close would do good...
Thanks,
Bhushan
-
November 16th, 2009, 02:59 PM
#2
Re: 3-tier windows application
-
November 17th, 2009, 05:09 AM
#3
Re: 3-tier windows application
Thanks for the links. I will look at them soon.
Meanwhile, I have got a sample on codeproject at:
This sample was developed in VS 2005, I believe. But, as always there are certain changes as MS changes versions. I have an issue with the Dataset designer code. In the sample, what the author does is, he puts it in a namespace DACF.DataLayer which happens to be the top namespace for the DataLayer project implemented as class library. And, in the dataset designer code, he has included all the table adapters' code in 2 different namespaces as under:
Code:
namespace DCAF.DataLayer
{
// All the attributes specified
public partial class CustomerOrderTDS : global::System.Data.DataSet
{ }
}
namespace DACF.DataLayer.CustomerOrderTDSTableAdapters
{
// All the attributes specified
partial public class CustomersTableAdapter : global::System.ComponentModel.Component
{ }
// All the attributes specified
partial public class OrdersTableAdapter : global::System.ComponentModel.Component
{ }
}
and their is another .cs file that implements the partial class CustomerOrderTDS as under:
Code:
using DCAF.DataLayer.CustomerOrderTDSTableAdapters;
namespace DCAF.DataLayer
{
partial class CustomerOrderTDS
{
public static CustomerOrderTDS GetCustomerOrders()
{
CustomersTableAdapter custAdapter = new CustomersTableAdapter();
OrdersTableAdapter ordAdapter = new OrdersTableAdapter();
CustomerOrderTDS ds = new CustomerOrderTDS();
custAdapter.Fill(ds.Customers);
ordAdapter.Fill(ds.Orders);
return ds;
}// End of method
}// End of class
}// End of namespace
In the above example, the dataset and datatable classes have been put in separate namespaces. Even though the namespace DACF.DataLayer.CustomerOrderTDSTableAdapters is not actually nested in the code inside the DACF.DataLayer namespace, it logically says so. And the class view shows the 2 namespaces as separate namespaces; albeit they are related and we can call them using the "." operator.
In my case, I am developing a similar application in VB.NET with a different database. And I have known that what can be in C# application can be easily done in VB.NET with a little more verbosity. However, when I try to create namespaces of the kind, the nested namespace is shown underneath the main project namespace in the class view. The above code in VB.NET becomes:
Code:
Namespace DCAF.DataLayer
'All the attributes specified
Public Partial Class CustomerOrderTDS Inherits Global.System.Data.DataSet
'Implementation
End Class
End Namespace
Namespace DACF.DataLayer.CustomerOrderTDSTableAdapters
'All the attributes specified
Partial Public Class CustomersTableAdapter
Inherits Global.System.ComponentModel.Component
'Implementation
End Class
'All the attributes specified
Partial Public Class OrdersTableAdapter Inherits global::System.ComponentModel.Component
'Implementation
End Class
End Namespace
' Please note that this is what I want to do. Right now there is no namespace differentiation.
and their is another .vb file that implements the partial class CustomerOrderTDS as under:
Code:
Imports DCAF.DataLayer.CustomerOrderTDSTableAdapters
Namespace DCAF.DataLayer
Partial Class CustomerOrderTDS
Public Shared Function GetCustomerOrders() As CustomerOrderTDS
Dim custAdapter As New CustomersTableAdapter()
Dim ordAdapter As New OrdersTableAdapter()
Dim ds As New CustomerOrderTDS()
custAdapter.Fill(ds.Customers) 'Getting an error here...
ordAdapter.Fill(ds.Orders) ' And here as well...
Return ds
End Sub
End Class
End Namespace
The same code however, shows the Namespaces as nested in the class view. I mean to say, in C# class view, these are logically nested but physically separate in code as well as in class view. But in VB.NET, although they are logically nested and physically separate in code, they are not physically separate in the class view!!! Hence, I can create a Namespace XYZ, inside a namespace XYZ which happens to be the project top level namespace XYZ. What I want is to emulate the same functionality as in C# to be implemented in VB.NET. Please let me know, how that can be done???
Also, why do we use the '::' scope resolution operator as in C++, in C# while dealing with global namespace? My understanding is, there is no such syntax in C#.
Please, let me know how to go about this problem, while I look at references posted here...
Thanks
Bhushan
-
November 17th, 2009, 02:31 PM
#4
Re: 3-tier windows application
Hi all,
It seems that Visual Basic has a different way of working...or atleast VS 2008. You need not mention the namespace that you are working in as we can in C#. Let us say we have a project named MyProj, then the default top level namespace for that project is "namespace MyProj{....}". So, in C#, we can write all the code in namespace MyProj{...} braces. But, if we do the same in VB.NET as Namespace MyProj.....End Namespace, then it creates a namespace with the same name inside MyProj! So to solve this problem, what I did was, I just did not include the default top level namespace for that project at all. And that worked....So that issue is solved...
The second Q regarding remains; but I will eventually find out I guess.
The third and new Q is regarding the same article at:
The C# code for Data Access Layer is summarized as under:
Code:
// The first part of the typed data set and the table adapter for Customers and Orders table
// is in CustomerOrderTDS.designer.cs file and the design is in CustomerOrderTDS.xsd
// This is the other part of the
using DCAF.DataLayer.CustomerOrderTDSTableAdapters;
namespace DCAF.DataLayer
{
partial class CustomerOrderTDS
{
public static CustomerOrderTDS GetCustomerOrders()
{
CustomersTableAdapter custAdapter = new CustomersTableAdapter();
OrdersTableAdapter ordAdapter = new OrdersTableAdapter();
CustomerOrderTDS ds = new CustomerOrderTDS();
custAdapter.Fill(ds.Customers);
ordAdapter.Fill(ds.Orders);
return ds;
}
}
}
//......
// This is the service class that connects the DAL classes to the Business Objects
using System;
using System.Collections.Generic;
using System.Text;
using DCAF.DataLayer.CustomerOrderTDSTableAdapters;
namespace DCAF.DataLayer
{
public class CustomerOrderService
{
#region "Storage"
private CustomersTableAdapter m_customersAdapter = null;
protected CustomersTableAdapter CustomersAdapter
{
get
{
if (m_customersAdapter == null)
{
m_customersAdapter = new CustomersTableAdapter();
}
return m_customersAdapter;
}
}
private OrdersTableAdapter m_ordersAdapter = null;
protected OrdersTableAdapter OrdersAdapter
{
get
{
if (m_ordersAdapter == null)
{
m_ordersAdapter = new OrdersTableAdapter();
}
return m_ordersAdapter;
}
}
#endregion "Storage"
#region "Public Interface
public CustomerOrderTDS.CustomersDataTable GetCustomers()
{ return CustomersAdapter.GetData(); }
public CustomerOrderTDS.OrdersDataTable GetOrders()
{ return OrdersAdapter.GetData(); }
public CustomerOrderTDS GetCustomerOrders()
{ return CustomerOrderTDS.GetCustomerOrders(); }
#endregion "Public Interface"
}
}
The Corresponding VB.NET code is as under...
Code:
' The first part of the typed data set and the table adapter for Customers and Orders table
' is in CustomerOrderTDS.designer.cs file and the design is in CustomerOrderTDS.xsd
' This is the other part of the
Imports DCAF.DataLayer.CustomerOrderTDSTableAdapters
Namespace DCAF.DataLayer
Partial Class CustomerOrderTDS
Public Shared Function GetCustomerOrders() As CustomerOrderTDS
Dim custAdapter As New CustomersTableAdapter()
Dim ordAdapter As New OrdersTableAdapter()
Dim ds As New CustomerOrderTDS()
custAdapter.Fill(ds.Customers)
ordAdapter.Fill(ds.Orders)
Return ds
End Function
End Class
End Namespace
'...
' This is the service class that connects the DAL classes to the Business Objects
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports DCAF.DataLayer.CustomerOrderTDSTableAdapters
Namespace DCAF.DataLayer
Public Class CustomerOrderService
#Region "Storage"
Private m_customersAdapter As CustomersTableAdapter = Nothing
Protected ReadOnly Property CustomersAdapter() As CustomersTableAdapter
Get
If m_customersAdapter Is Nothing Then
m_customersAdapter = New CustomersTableAdapter() 'Error here...
End If
Return m_customersAdapter
End Get
End Property
Private m_ordersAdapter As OrdersTableAdapter = Nothing
Protected ReadOnly Property OrdersAdapter() As OrdersTableAdapter
Get
If m_ordersAdapter Is Nothing Then
m_ordersAdapter = New OrdersTableAdapter() 'Error here...
End If
Return m_ordersAdapter
End Get
End Property
#End Region
#Region "Public Interface
Public Function GetCustomers() As CustomerOrderTDS.CustomersDataTable
Return CustomersAdapter.GetData()
End Function
Public Function GetOrders() As CustomerOrderTDS.OrdersDataTable
Return OrdersAdapter.GetData()
End Function
Public Function GetCustomerOrders() As CustomerOrderTDS
Return CustomerOrderTDS.GetCustomerOrders()
End Function
#End Region
End Class
End Namespace
The C# application was developed in VS 2005 and I got it migrated to VS 2008.
While the code in C# works fine, the one in VB.NET code has underlines indicating the error:
"value of type DCAF.DataLayer.CustomerOrderTDSTableAdapters.CustomersTableAdapter cannot be converted to 'i-dimensional array of DCAF.DataLayer.CustomerOrderTDSTableAdapters.CustomersTableAdapter'
and similar error for Orders data adapter
"value of type DCAF.DataLayer.CustomerOrderTDSTableAdapters.OrdersTableAdapter cannot be converted to 'i-dimensional array of DCAF.DataLayer.CustomerOrderTDSTableAdapters.OrdersTableAdapter'
Is it dependent on the contents of the data table, that the object returned by table adapter will vary accordingly?
Is there another way to deal with this problem? I doubt that I am doing something wrong in syntax? Or is it wrong in C# as well?
Thanks & regards,
Bhushan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|