TIP
💡 Learn more : Azure storage account overview (opens new window).
# Deleting an item from a Azure Storage Table
In case you are new to the Azure Storage Tables, we've reviewed the following items this week:
- Creating your first Azure Storage Table (opens new window)
- Adding an item to a Azure Storage Table (opens new window)
- Reading an item from a Azure Storage Table (opens new window)
- Updating an item from a Azure Storage Table (opens new window)
- Deleting an item from a Azure Storage Table (opens new window)]
Today, we'll be taking a look at deleting an item through C# code into an Azure Storage Table.
# Getting Started
Open the C# Console application that we were working with last week (opens new window) and let's add a method to:
- Delete an item based off of the table, RowKey and PartitionKey that we pass in.
# Delete an item
In our Program.cs
file, we'll now add in a helper method that passes in a table, RowKey and PartitionKey to identify the message we want to delete.
static void DeleteMessage(TableClient table, string partitionKey, string rowKey)
{
table.DeleteEntity(partitionKey, rowKey);
}
1
2
3
4
2
3
4
In this example, we retrieve the message and then delete the entity.
# Putting it all together.
The Main method inside of the Program.cs
file, we'll call our helper method.
static void Main(string[] args)
{
var serviceClient = new TableServiceClient(ConfigurationManager.AppSettings["StorageConnection"]);
TableClient table = serviceClient.GetTableClient("thankfulfor");
table.CreateIfNotExists();
//added these lines
DeleteMessage(table, "ThanksApp", "I am thankful for the time with my family");
Console.ReadKey();
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11