Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Passing Data throught database

$
0
0

I'm trying to pass the data to another activity, the data is from database. And I'm having an error, and IDK why, can someone explain it to me?

This is how i Put the Extra:

private void Log_Click(object sender, System.EventArgs e)
{
try
{
string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Person.db");
var db = new SQLiteConnection(dpPath);
var data = db.Table();

            var data1 = data.Where(x => x.username == txtUser.Text && x.password == txtPass.Text).FirstOrDefault();

            if (data1 != null)
            {
                Intent openAct = new Intent(this, typeof(personAccount));
                this.StartActivity(openAct);
                openAct.PutExtra("info", JsonConvert.SerializeObject(information));
            }
            else
            {
                Toast.MakeText(this, "Username or Password invalid", ToastLength.Short).Show();
            }
        }
        catch (Exception ex)
        {
            Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();
        }
    }

This is how i get the extra:

IdQR = FindViewById(Resource.Id.QRCode);
LogedPerson = JsonConvert.DeserializeObject(Intent.GetStringExtra("info"));
IdQR.Text = LogedPerson.id.ToString();

This is my class:

public class info
{

    [PrimaryKey, AutoIncrement, Column("_Id")]
    public int id { get; set; }
    [MaxLength(25)]
    public string username { get; set; }
    [MaxLength(15)]
    public string password { get; set; }
    public byte [] image { get; set; }
}

I followed this tutorial image

But his data is Json and he serialize it, I guess that part is the reason why I'm having an error.

Thanks in advance :)


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>