我已经编写了一些 C# 代码来将数据存储到超表数据库中。但是我不知道如何更新数据。以下是我所做的:
Hypertable b = new Hypertable();
b.Write("1", "value1");//this line is for writing to database
b.Write("1", "value111");//this line is for updating the value whose key = "1"
我的写功能是:
public override bool Write(string key, string value)
{
try
{
using (IContext context = Context.Create(connectionString))
using (IClient client = context.CreateClient())
{
using (INamespace ns = client.OpenNamespace("Test", OpenDispositions.OpenAlways | OpenDispositions.CreateIntermediate))
{
using (ITable table = ns.OpenTable(tableName))
{
using (ITableMutator mutator = table.CreateMutator())
{
Key _key = new Key { Row = key, ColumnFamily = "vvalue" };
mutator.Set(_key, Encoding.UTF8.GetBytes(value));
}
}
}
}
return true;
}
catch (Exception e)
{
Console.WriteLine("Hypertable--Write--{0}", e.Message);
return false;
}
}
所以我的更新只是用相同的键但不同的值再次写入。但是在更新后我读取了那个键和值,它应该显示新的键和值(键 =“1”和值 =“value111”)但它没有,它只显示旧的键和值(key = "1" and value = "value1")
我不知道为什么会这样。任何提示将不胜感激。谢谢。