When to create User Defined Data Type in VB.Net
I have many different objects in my project like Events, NewsArticles, Subscribers, MailingLists, Addresses, Venues, FAQ collections, FAQQuestions, Songs, Statistics, Different types of reports, Categories of different types (Events, Venues) and so on. When should I consider using objects (classes) or data types (structures)?
Re: When to create User Defined Data Type in VB.Net
We basically create the user defined data type in the following situatione:
- The object should just carry data from 1 layer to another and that is it.
- There should be a business layer that the object is given to. This deals with any custom logic/validation to the object with any business rules needed to be applied.
- Once the business layer gets done with the object, it sends it to the data access layer which does any database validation/rules and sends it to the database.
Re: When to create User Defined Data Type in VB.Net
The process of creating a UDT begins with creating a .NET class that supports the proper API. Creating and using a UDT comes in two phases: creating the library and registering the UDT with SQL Server. The first step is to create your new data type in Visual Studio .NET. The listing for this article shows how to create a Social Security Number data type. When you create your UDT you will do the following:
- Create a new class library
- Import assembles
- Add two attributes to your class (Serializable() and SqlUserDefinedDataType)
- Implement the INullable interface
- Add required methods and properties to your class
- Compile your class
- Register your class library with SQL Server
Re: When to create User Defined Data Type in VB.Net
Users can define their own data types. Classes and structure definitions fall under user defined data types. If we want to play with user defined datatypes and ViewState, then really we need to concentrate on defining them.
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CodeProject
{
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
UserClass UC=new UserClass();
this.ViewState["Key"]=UC;
Response.Write("View State is workng..");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
public class UserClass
{
public UserClass()
{
_number=1;
_name="cp.com";
}
private int _number;
private string _name;
}
}