使用Android Xamarin SQLite访问特定的列数据

代码老虎

我正在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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Xamarin (IOS Android UWP) 与 SQlite 使用 OneToMany

访问 Xamarin Forms SQLite 对象中的数据时是否需要使用锁定对象?

Xamarin Forms - 使用 SQLite

使用 SQLite 数据 Xamarin 填充元组列表

Xamarin Android C#SQLite

SQLite似乎不再可以在Xamarin Android上使用

使用Sqlite.net Pcl为Xamarin android升级数据库

使用外键从游标从SQLite检索数据-Android C#Xamarin

如何使用SQLite.Net在Xamarin.Android中创建,插入和绘制数据?

Android(Xamarin)特定的穿戴布局

使用Xamarin.Forms从Sqlite数据库获取数据

Xamarin Visual Studio Android设置SQLITE数据库

如何通过Xamarin Forms代码从Android Fragment打开或访问数据?

Xamarin.Forms Using SQLite - 如何更新特定列的所有数据?

Xamarin.Android-SQLite ORM查询的挑战

Xamarin Android Sqlite Db 浏览器

Xamarin Android C#SQLite参数查询

Xamarin Forms Sqlite Android 7+支持

Xamarin Android 更改可访问性焦点

xamarin android项目访问PCL功能

Xamarin Android-写入文件-拒绝访问

拒绝访问路径(Xamarin / Android)

访问路径...被拒绝-Xamarin Android

在Xamarin Android中访问UI线程

Xamarin Android - 在片段内访问 textview onclick

从SQLITE Android中的特定列获取所有数据

如何使用Xamarin Android LocalBroadcastManager

Xamarin Android WindowSoftInput调整大小(特定页面)

如何使用DependencyService和Interface的委托将xamarin.android特定功能的方法传递给xamarin.forms?