TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ghasem deh
NA
258
39.7k
Errors in the existing database in the project Xamarin !
Nov 29 2016 10:22 AM
Hi guys
I'm gonna use my existing database in the project but I get an error
I used "https://www.nuget.org/packages/sqlite-net-pcl" in my project
this DB class :
public
static
SQLiteConnection sqliteCon()
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string dbPath = Path.Combine(path,
"fitnessDBupdate.db"
);
CopyDatabaseIfNotExists(dbPath);
using
(var conn =
new
SQLiteConnection(dbPath,
true
))
{
return
conn;
}
}
public
bool
createMembers()
{
try
{
using
(var conn = sqliteCon())
{
conn.CreateTable<Members>();
}
return
true
;
}
catch
(SQLiteException ex)
{
Log.Info(
"SQLite EX"
, ex.ToString());
return
false
;
}
}
private
static
void
CopyDatabaseIfNotExists(string dbPath)
{
try
{
string dbName =
"fitnessDBupdate.db"
;
dbPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(), dbName);
// Check if your DB has already been extracted.
if
(!File.Exists(dbPath))
{
using
(BinaryReader br =
new
BinaryReader(Application.Context.Assets.Open(dbName)))
{
using
(BinaryWriter bw =
new
BinaryWriter(
new
FileStream(dbPath, FileMode.Create)))
{
byte[] buffer =
new
byte[2048];
int
len = 0;
while
((len = br.Read(buffer, 0, buffer.Length)) > 0)
{
bw.Write(buffer, 0, len);
}
}
}
}
}
catch
(SQLiteException ex)
{
Log.Info(
"SQLite Ex"
, ex.ToString());
}
}
and in login activity :
using
Android.App;
using
Android.OS;
using
Android.Widget;
using
ExsitingSQLite.Resources.DataHelper;
using
System;
using
System.Linq;
namespace
ExsitingSQLite
{
[Activity(Label =
"ExsitingSQLite"
, MainLauncher =
true
, Icon =
"@drawable/icon"
)]
public
class
MainActivity : Activity
{
Button btnRegister;
Button btnLog;
EditText edtName;
EditText edtPass;
DataBase db;
protected
override
void
OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
// ????? ????? ??
btnRegister = FindViewById<Button>(Resource.Id.btnRegisterPage);
btnLog = FindViewById<Button>(Resource.Id.btnLogin);
edtName = FindViewById<EditText>(Resource.Id.edtName);
edtPass = FindViewById<EditText>(Resource.Id.edtPass);
// ????????
btnRegister.Click += btnRegister_Click;
btnLog.Click += btnLog_Click;
}
private
void
btnLog_Click(object sender, EventArgs e)
{
db =
new
DataBase();
var data = db.listMembers();
var data2 = data.Where(x => x.fullName == edtName.Text && x.password == edtPass.Text).FirstOrDefault();
//Linq Query
if
(data2 != null)
{
StartActivity(typeof(HomeActivity));
}
else
{
Toast.MakeText(
this
,
"??? ?????? ?? ???? ???? ?? ????? ???"
, ToastLength.Short).Show();
}
}
private
void
btnRegister_Click(object sender, EventArgs e)
{
StartActivity(typeof(RegisterActivity));
}
}
}
thanks
Reply
Answers (
4
)
project about question paper generation in asp.net
Help How to Send Variables, read comments