【发布时间】:2020-10-20 16:25:39
【问题描述】:
我正在 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``` 中输入的另一个值进行比较
【问题讨论】:
-
Stock表是否有email列?您发布的课程定义是针对Person,而不是Stock -
@Jason,编辑中好点
-
现在很好,我只想要代码,我将使用它从表中选择电子邮件并将其与 EditText 中输入的值进行比较