【发布时间】:2017-08-14 11:31:40
【问题描述】:
我正在使用 Xamarin,我的代码是:
DatabaseUpdates updatedb = new DatabaseUpdates();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ProjectListViewPage);
updatedb.SetContext(this);
//db = new ProjectDatabaseFunctions();
// db.CreatDataBaseProject();
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
lstData = FindViewById<ListView>(Resource.Id.listView);
Log.Info("DB_Path", folder);
LoadData();
lstData.ItemClick += (s, e) =>
{
var ID = lstSource.Where(xc => xc.ID == e.Id).Select(cx => cx.ID);
FragmentTransaction transation = FragmentManager.BeginTransaction();
listMenuProject list = new listMenuProject(ID.ToString());
list.Show(transation, "dialog fragment");
};
}
private void LoadData()
{
lstSource = updatedb.selectTableProject();
var adapter = new ListViewAdapterProject(this, lstSource);
lstData.Adapter = adapter;
}
这是我从列表中单击的内容中获取 ID 的地方。有了这个 ID,我需要从该 ID 中获取所有值,因此我编辑该数据,并且还需要创建一个具有相同列表的列表。
目前我写的代码是。
public class DatabaseUpdates
{
private ProjectDatabase _helper;
public void SetContext(Context context)
{
if (context != null)
{
_helper = new ProjectDatabase(context);
}
}
public bool insertIntoTableProject(Project proj)
{
try
{
using (var connection = new SQLiteConnection(_helper.WritableDatabase.Path))
{
connection.Insert(proj);
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
public List<Project> selectTableProject()
{
try
{
using (var connection = new SQLiteConnection(_helper.ReadableDatabase.Path))
{
return connection.Table<Project>().ToList();
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return null;
}
}
public bool deleteTableProject(int proj)
{
try
{
using (var connection = new SQLiteConnection(_helper.WritableDatabase.Path))
{
connection.Delete(proj);
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
【问题讨论】:
标签: c# sqlite xamarin android-sqlite