【发布时间】:2021-12-30 00:25:56
【问题描述】:
我正在寻找一个简单的 C# 程序来将数据插入 Azure blob 表存储。 有人可以帮忙吗?
请让我知道下面的代码有什么问题?(代码没有抛出任何错误,只是没有创建任何表/插入数据)
using System;
using System.Threading.Tasks;
using Azure.Data.Tables;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using TableEntity = Microsoft.WindowsAzure.Storage.Table.TableEntity;
using TableClientConfiguration = Microsoft.Azure.Cosmos.Table.TableClientConfiguration;
public class CustomerEntity : TableEntity
{
public CustomerEntity(string lastName, string firstName)
{
this.PartitionKey = lastName;
this.RowKey = firstName;
}
public CustomerEntity() { } // the parameter-less constructor must be provided
public string Email { get; set; }
public string PhoneNumber { get; set; }
}
class Program
{
static void Main(string[] args) {
var tableName = "TestTempTable";
var storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=**********;AccountKey=*******/****==;EndpointSuffix=core.windows.net";
try
{
Console.WriteLine("START");
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference(tableName);
table.CreateIfNotExistsAsync();
Console.WriteLine($"CloudTable name is : {tableClient}");
// Create a new customer entity.
CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");
customer1.Email = "xyz@xyz.com";
customer1.PhoneNumber = "1234568";
table.ExecuteAsync(TableOperation.Insert(customer1));
Console.WriteLine("Records Inserted");
Console.WriteLine("END");
}
catch (Exception e)
{
Console.WriteLine("Encountered Exception - "+e);
}
}
}
谢谢, 保罗。
【问题讨论】:
-
请编辑您的问题并包含您目前编写的代码和您正在使用的 SDK。