如何检查数据库中是否已存在记录(ContentValues
)?
public void insertData(String ActId,String Dstcode,String Mandicode,String Traderlicno,String licenseId,String licensename,String Gatepassno,String FarmerId,String Farmername,String FarmerFatherName,String CommodityGrpCode,String CommodityCode,String VartyCode,String Cwght,String UntCode,String FnlPrice,String lgndate,String Ip,String dte,String IEMIN0,String ModelNo,String BoardName,String BrandName,String SIMNo)
{
ContentValues cv = new ContentValues();
cv.put(DatabaseHandler.AUCTIONINFO_ActId, ActId);
cv.put(DatabaseHandler.AUCTIONINFO_Dstcode, Dstcode);
cv.put(DatabaseHandler.AUCTIONINFO_Mandicode, Mandicode);
cv.put(DatabaseHandler.AUCTIONINFO_Traderlicno, Traderlicno);
cv.put(DatabaseHandler.AUCTIONINFO_licenseId, licenseId);
cv.put(DatabaseHandler.AUCTIONINFO_licensename, licensename);
cv.put(DatabaseHandler.AUCTIONINFO_Gatepassno, Gatepassno);
cv.put(DatabaseHandler.AUCTIONINFO_FarmerId, FarmerId);
cv.put(DatabaseHandler.AUCTIONINFO_Farmername, Farmername);
cv.put(DatabaseHandler.AUCTIONINFO_FarmerFatherName, FarmerFatherName);
cv.put(DatabaseHandler.AUCTIONINFO_CommodityGrpCode, CommodityGrpCode);
cv.put(DatabaseHandler.AUCTIONINFO_CommodityCode, CommodityCode);
cv.put(DatabaseHandler.AUCTIONINFO_VartyCode, VartyCode);
cv.put(DatabaseHandler.AUCTIONINFO_Cwght, Cwght);
cv.put(DatabaseHandler.AUCTIONINFO_UntCode, UntCode);
cv.put(DatabaseHandler.AUCTIONINFO_FnlPrice, FnlPrice);
cv.put(DatabaseHandler.AUCTIONINFO_lgndate, lgndate);
cv.put(DatabaseHandler.AUCTIONINFO_Ip, Ip);
cv.put(DatabaseHandler.AUCTIONINFO_dte, dte);
cv.put(DatabaseHandler.AUCTIONINFO_IEMIN0, IEMIN0);
cv.put(DatabaseHandler.AUCTIONINFO_ModelNo, ModelNo);
cv.put(DatabaseHandler.AUCTIONINFO_BoardName, BoardName);
cv.put(DatabaseHandler.AUCTIONINFO_BrandName, BrandName);
cv.put(DatabaseHandler.AUCTIONINFO_SIMNo, SIMNo);
database.insert(DatabaseHandler.TABLE_AUCTIONINFO, null, cv);
}
答案 0 :(得分:0)
修改强>
myDB= openOrCreateDatabase("DBName", MODE_PRIVATE, null);
myDB.execSQL("CREATE TABLE IF NOT EXISTS MyTable (your query goes here);");
Cursor cursor = myDB.rawQuery("select AUCTIONINFO_ActId from TABLE_AUCTIONINFO where AUCTIONINFO_licenseId = licenseId;", null);
if(cursor.getCount()!=0)
{
// now you can insert the record
}
else
{
}