2014-01-22 84 views
0

我有以下几点:平板设备内部如何插入和使用的SQLite SQLite的更新净

 
tblCustomer 

ID CompanyName Group  Product group GST 
-- ----------- ------- ------------- ---- 
1 The One  Exp  A    4  
2 The One  Exp  A    8  
. 
. 
20 

2)SQLite的-DB:在后端服务器

1)的SQL Server。

 

tblCustomer 

ID CompanyName Group  Product group GST 
-- ----------- ------- ------------- ---- 
1 The One  Exp  A    4  
2 The One  Exp  A    8 
. The One 
. 
20 The One 

3) 我使用Web服务从服务器获取数据,并使用下面的代码

 

The Problems: 

1). How to I update the tblCustomer in SQLite for changes below: 

Note: ID in SQL sever and Sqlite ARE not the same. 


ID CompanyName Group  Product group GST 
-- ----------- ------- ------------- ---- 
1 The One  Exp  A    6 < -- before it was 4 


2) Someone add data in SQL Server and the total record is 21 now. 

How to add this record in SQLite tbl customer? 


foreach (var client in Customers) 
{ 
InsertNewCustomer(client.Company, client.Group, client.ProductGroup, client.GST) 
} 


private void InsertNewCustomer(string Company,string Grp, string PGrp, int Gst) 
{ 


1) How to create SQL Statement for this case? 

var existingCustomer = (db2.Table<Customer>().Where(c => c.No == Company)) ??? 

if (existingCustomer != null) 
    { 

    ??-- how to handle? 


    int success = db2.Update(existingCustomer); 

    } 
    else 
    { 
     int success = db2.Insert(new Customer() 
     { 
      Name = Company, 
      Group = Grp, 
      ProductGroup = PGrp, 
      GST = Gst 

     }); 
    } 

} 

回答

0

1)更新tblCustomer SET GST = 6,其中插入使用SQLite-Net的API记录到的SQLite Db的ID = 1; 2)您需要执行如下SQLite语句: INSERT INTO tblCustomer(CompanyName,Group,[Product group],GST)VALUES('Newcompany','EXP','A',2);

3)与1相同,但是 UPDATE tblCustomer SET CompanyName ='Newcompany',Group ='EXP',[Product group] ='A',GST = 6 WHERE ID = 1;

当然,你必须更换 'Newcompany', 'EXP',ID = 1 ...您的实际数据

+0

在SQL服务器和SQLite中的ID是不一样的。你能用SQLITE-Net的方法展示我吗? – MilkBottle