SIGN UP MEMBER LOGIN:    
ARTICLE

Inserting a Null Value for Integer columns in Windows Azure Table

Posted by Dhananjay Kumar Articles | Cloud Computing October 17, 2011
This post will focus on providing null values for integer columns.
Reader Level:

There may be a requirement when you need to insert null values for values type columns in an Azure table. In our recent project, we had a requirement to insert null values for integer columns. Usually if you don't provide any value to Integer variable, it would get initialized as 0, since they are value type's variables. This post will focus on providing null values for integer columns

First ,you need to define an entity as below,

WinAzrtbl1.gif

You may have noticed that I am making integer properties as Nullable types

WinAzrtbl2.gif

Now create an Azure table as below,

WinAzrtbl3.gif

Then you can insert a null value for the integer columns as below,

WinAzrtbl4.gif

For your reference, the full source code to insert a null values is below,

using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {          
            CloudStorageAccount account = CloudStorageAccount.Parse("connectionString");
            CloudTableClient tableClient = new CloudTableClient(
                                          account.TableEndpoint.ToString(),
                                           account.Credentials);          
            string tableName = "School";
            tableClient.CreateTableIfNotExist(tableName);

          
            TableServiceContext  context = tableClient.GetDataServiceContext();
            SchoolEntity entity = new SchoolEntity
                                   {
                                       Age = null,
                                       Name = "DJ",
                                       PartitionKey = "S",
                                       RollNumber  = null ,
                                       RowKey = Guid.NewGuid().ToString()
                                   };           

            context.AddObject(tableName, entity);
            context.SaveChanges();

            Console.WriteLine("Saved");
            Console.ReadKey(true);                     

          }
    }

    public class SchoolEntity : TableServiceEntity
    {
        public string Name { get; set; }
        public int ? RollNumber { get; set; }
        public int ? Age { get; set; }
    }

}

In this way you can insert null values. I hope this post was useful. Thanks for reading.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor