bhushan1980
November 17th, 2009, 01:46 PM
Hi all,
I am primarily used to work in C#(about 75% times). But I also have to work with VB.NET quite often for some justified reasons.
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. Likewise, there are a lot of things in VB.NET that are automatically done for us.
My Q is regarding the DAL article at:
http://www.codeproject.com/KB/database/CustomBindableObject.aspx
Since the code is in C#, it is summarized as under:
// 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...
' 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 (I have commented the 2 lines):
"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?
Also, I do not have a working sample yet; as I am saying this based on the underlines I am getting in the IDE.
Thanks & regards,
Bhushan
I am primarily used to work in C#(about 75% times). But I also have to work with VB.NET quite often for some justified reasons.
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. Likewise, there are a lot of things in VB.NET that are automatically done for us.
My Q is regarding the DAL article at:
http://www.codeproject.com/KB/database/CustomBindableObject.aspx
Since the code is in C#, it is summarized as under:
// 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...
' 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 (I have commented the 2 lines):
"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?
Also, I do not have a working sample yet; as I am saying this based on the underlines I am getting in the IDE.
Thanks & regards,
Bhushan