Saturday, August 30, 2014

How to Add Default Constraints in SQL

Syntax:

create table [Table_Name] (
[Column_Name] [dataType] constraint [Constraint_Name]
Default [Default_Value]
)

The Following example show how to add constraints during table creation process

create table MyTable(
id int not null constraint ConstID
Default 1,
name nvarchar(20)
)

The Following example show how to add constraints after the table has been created

alter table MyTable
add constraint MyConst
Default 'Default Value' for name

I hope it was informative for you and I would like to Thank you for reading

Monday, August 25, 2014

Storing different types in An Array C#

In this tutorial I will show you how can we store different types in An Array using C#

            int[] arr = new int[3];
            arr[0] = 0;
            arr[1] = "String";   <----  Not Allowed because Array type in Int and we are storing String

Now in order to store different types we will need to make an Array of type Object, because all types are inherited from Object hence we can store any type in Array

            object[] OArr = new object[3];
            OArr[0] = 1;
            OArr[1] = "String";    //   <----- We can store string because Array type is Object

We can also stored Class object in this Array

I hope it was informative for you and I would like to Thank you for reading.