[英]WCF ado.net Insert record (at end)
堆高车
我困扰这个问题已经很长时间了,以至于我终于决定在这里发表我的问题。
这真是困扰我。 我正在为Windows Phone 8编写一个应用程序。该应用程序围绕本地和远程数据库运行。 本地数据库部分是简单的部分。 但是现在,我想使用WCF服务将记录插入到远程数据库中(在服务器端将ADO.NET与服务一起使用)。 我已经成功地在远程数据库中插入了记录,但是有一个问题(我要瞄准的目标至少是这样)。
我的数据库表(即时消息插入其中)具有主键,并且在将数据插入数据库时我不想告诉/插入此主键。 我只想在最后一条记录之后插入新记录。 有什么办法吗?
这是我到目前为止所拥有的:
private MeasurementEntities Context;
Context = new MeasurementEntities(new Uri("http://192.168.11.240:85/NFCDataService.svc/"));
public void SaveAnwsersToDbLocal(bool ans1, bool ans2, bool ans3)
{
Measurement temp = new Measurement();
temp.Anwser1 = ans1;
temp.Anwser2 = ans2;
temp.Anwser3 = ans3;
temp.MeasurementId = 1; // this is the primary key, and want to get rid of this.
// i want to insert at end of database. but how?
// add to local collection.
_MeasurementCollection.Add(temp);
Context.AddToMeasurements(temp);
Context.BeginSaveChanges(SaveChangesCallback, temp);
//if wifi is on:
UploadMeasurements();
}
好吧,这真是愚蠢。 在我的mssql表中,我没有启用该功能来添加具有自动增量的行。 Atleast,我启用了它,但增量设置为0。因此它将指向同一记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.