我正在Xamarin Android中建立登录活动,并且我已插入所有模块(库和文件)并准备就绪,但是我在从表中检索单个对象(实际上是电子邮件)时遇到了问题(它已包含数据)。我的代码解释如下...
//The class that acts as a blueprint to the table is this one
class Person {
[PrimaryKey, AutoIncrement]
public int id { set; get; }
public string name { set; get;}
public string department { set; get; }
public string email { set; get; }
public string password { set; get; }
}
处理登录逻辑的文件
class Login : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState){
//Login button definition
Button login=(Button)FindViewById<Button>(Resource.Id.login);
//Make the button raise login event on click
login.Click +=Login; }
}
//Button method for login
private void Login(object sender, EventArgs e){
//Define location that the connection will use to create and store tables
string dbpath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "dbpersons.db");
//Define new connection to database using a connection string
var conn=new SQLite.SQLiteConnection(dbpath);
try{
//Microsoft manual says this can access elements of a row using id parameter
var stock = db.Get<Person>(5);
// I need code that will let me access email from specific column in table
}catch(SQLite.SQLiteException m){
//Display exception in a toast
Toast.MakeText(Application.Context,m.Message,ToastLength.Long).Show();
}
}
}
我需要该电子邮件与另一个值用户进行比较,该用户将在“ EditText”中输入
您正在从数据库中检索对象,因此要访问该对象的属性,只需使用该属性
var stock = db.Get<Person>(5);
// I need code that will let me access email from specific column in table
var email = stock.email;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句