大家好我已經在xamarin中實現了sqlite數據庫,我需要搜索任何specfic數據存在或不在數據庫中。如何檢查數據是否存在或不在xamarin數據庫
我要檢查,如果數據或行是有或沒有在數據庫根據專輯密鑰
這裏是我的數據庫類
namespace FacebookAuth
{
class DatabaseHelper
{
Java.IO.File dir = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/Android/data/com.abhijit.testing.app/databases");
public bool createDataBase()
{
try
{
using (var connection = new SQLiteConnection(Path.Combine(dir.AbsolutePath, "album.db")))
{
connection.CreateTable<AlbumTable>();
return true;
}
}
catch (SQLiteException e)
{
return false;
}
}
public bool InsertIntoTable(AlbumTable album)
{
try
{
System.Console.Write("Data Saved Successfully");
using (var connection = new SQLiteConnection(Path.Combine(dir.AbsolutePath, "album.db")))
{
connection.Insert(album);
return true;
}
}
catch (SQLiteException e)
{
return false;
}
}
public List<AlbumTable> getalldata()
{
try
{
using (var connection = new SQLiteConnection(Path.Combine(dir.AbsolutePath, "album.db")))
{
return connection.Table<AlbumTable>().ToList();
}
}
catch (SQLiteException ex)
{
return null;
}
}
public List<AlbumTable> SelectAlbum(string orderid)
{
try
{
using (var connection = new SQLiteConnection(Path.Combine(dir.AbsolutePath, "album.db")))
{
return connection.Query<AlbumTable>("SELECT * From album Where AlbumKey=?", orderid);//not working exception raised that invalid table name
}
}
catch (SQLiteException ex)
{
return null;
}
}
public bool DeleteFromTable(AlbumTable album)
{
try
{
System.Console.Write("Data Saved Successfully");
using (var connection = new SQLiteConnection(Path.Combine(dir.AbsolutePath, "album.db")))
{
connection.Delete(album);
return true;
}
}
catch (SQLiteException e)
{
return false;
}
}
}
}
和數據庫中的列名如下
K
class AlbumTable
{
[PrimaryKey]
public string Id { get; set; }
public string ZipFillPath { get; set; }
public string CoverPhotoPath { get; set; }
public string AlbumKey { get; set; }
public string NoOfPages { get; set; }
public string Email { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string City { get; set; }
public string Address1 { get; set; }
public string ZipPostalCode { get; set; }
public string PhoneNumber { get; set; }
}
如何檢查值出現在DB或不
作爲第一步,您應該爲類DatabaseHelper添加一個新方法getAlbum(字符串albumKey)。 returntype必須是AlbumTable。 – JRB