VKinfotek Inc.
  • Us
    About Us
    Contact Us
  • FAQs
  • Ready Software
    Ready ERP ASP Core Software for Azure Cloud
    Ready Web ERP Software
    Ready ASP.Net Azure Software
    Ready C# SQL Server Accounting Software
    Ready ASP.Net MVC and EF Software
First slide
Earn $100/hour in USA! Click Here

Q78: How to create a table using a simple C# Console application?

Open Visual Studio and create a C# Console application from the standard template.

new project dialog

By default, the created project will not have a reference to the storage library, but we can add that easily using the NuGet package manager. Right-click on the project and select 'Manage NuGet Packages' from the context menu. This will load up the Package Manager UI. Select the 'Online' tab from the Package Manager dialog, and search for 'Azure Storage'. Select the Windows Azure Storage package and click 'Install'.

manage Nuget dialog

After adding references of the Windows Azure Storage Client Library, you need to add the following namespaces. Open the program.cs file and add the following statements to the top of the file.

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;

class Program
{
	static void Main(string[] args)
	{
		//Add the following to the Main method:

try
{
	CloudStorageAccount account = CloudStorageAccount.Parse(
			CloudConfigurationManager.GetSetting(“StorageConnectionString”));
    
	CloudTableClient client = account.CreateCloudTableClient();

	CloudTable table = client.GetTableReference(“items”);

	table.CreateIfNotExists();
	Console.WriteLine(table.Uri.ToString());
}

catch (Exception ex)
{
    Console.WriteLine(ex);
}
	Console.WriteLine(“Done... press a key to end.”);
	Console.ReadKey();
}



Explanation of code: Create an instance of CloudStorageAccount. The CloudStorageAccount object is the root object we use to access to any of the storage sub systems: Blobs, Queues and Tables.

CloudStorageAccount account = CloudStorageAccount.Parse(
			CloudConfigurationManager.GetSetting(“StorageConnectionString”));


After creating an object of the storage account, we need to create an instance of the CloudTableClient. We create it as follows:

 
CloudTableClient tableClient = account.CreateCloudTableClient();


The last step in creating the Azure Table is to make a reference of the CloudTable and create it if it does not exist. ‘Items’ is the name of the table that we intend to create here.

CloudTable table = tableClient.GetTableReference("items");
table.CreateIfNotExists();


The code creates a CloudTable object using the GetTableReference method of the CloudTableClient object. The statement table.CreateIfNotExists(), will make a call to the Table service REST API and, if a table named 'items' does not exist within the storage account it will be created. Remember that the Table service is a REST based API. We have created a table, and next, we will add entities to it.
  • Prev Question
  • Next Question

See More Questions and Answers on - Azure Table Storage (cont..)

  • How to access the Azure table storage from a .NET application?
  • What is an Azure storage connection string?
  • How to configure Azure connection strings?
  • How to configure Azure connection strings for connecting to the storage emulator?
  • How to create a table in Azure storage?
  • How to insert entities into the Azure table?
  • How do I retrieve a single entity from table storage using tableoperation?
  • How do I query azure table storage using TableQuery class?
  • How to update records in a table storage?

Back to Master List of 100+ Questions and Answers

People also viewed: cover image of book develop erp software using asp core and deploy to Azure Create your own ERP Software using ASP Core>>
cover image of azure cloud book Create your own Azure SOM Software>>
cover image of asp.net book Create your own ERP Software using ASP .Net and SQL>>
cover image of foundation database programming book Create your own Accounting Software using C# >>
cover image of entity framework book Create your own SOM using Entity Framework MVC >>

  • SITEMAP
  • Terms of use
  • Testimonials

Back to top

Copyright © 2018 - All Rights Reserved - VKInfotek.com