Xamarin Forms SQlite ID AutoIncrement Not Working
up vote
0
down vote
favorite
I am trying to insert some values into sqlite database. ID has primarykey,autoincrement properties. First value has inserted successfully. When inserting for the second time, ID is not incrementing.So values are inserted again and again,not updating.I have installed sqlite-net-pcl library.Help Please..
using PCLStorage;
using SQLite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
public class SQLHelper
{
static object locker = new object();
readonly SQLiteConnection database;
public SQLHelper()
{
database = GetConnection();
// create the tables
database.CreateTable<Offline>();
database.CreateTable<Category>();
database.CreateTable<Product>();
database.CreateTable<Password>();
}
public SQLiteConnection GetConnection()
{
SQLiteConnection sqlitConnection;
var sqliteFilename = "Offline.db";
IFolder folder = PCLStorage.FileSystem.Current.LocalStorage;
string path = PortablePath.Combine(folder.Path.ToString(),
sqliteFilename);
sqlitConnection = new SQLite.SQLiteConnection(path);
return sqlitConnection;
}
public long Save_password(Password password)
{
lock (locker)
{
if (password.p_id != 0)
{
return database.Update(password);
}
else
{
return database.Insert(password);
}
}
}
}
public class Password
{
[PrimaryKey,AutoIncrement]
public long p_id { set; get; }
public string password { get; set; }
public string type { get; set; }
public string tb_num { get; set; }
}
cs page:
string lbl_1 = e1.Text;
string lbl_2 = e2.Text;
if (lbl_1.Equals(lbl_2))
{
Password password = new Password();
password.password = lbl_2;
long i = App.Database.Save_password(password);
if (i > 0)
{
Debug.WriteLine(i);
DependencyService.Get<IToast>().LongAlert("Success");
}
Navigation.PopAsync();
}
else
{
DependencyService.Get<IToast>().LongAlert("Passwords Mismatch!");
}
sqlite xamarin xamarin.forms
add a comment |
up vote
0
down vote
favorite
I am trying to insert some values into sqlite database. ID has primarykey,autoincrement properties. First value has inserted successfully. When inserting for the second time, ID is not incrementing.So values are inserted again and again,not updating.I have installed sqlite-net-pcl library.Help Please..
using PCLStorage;
using SQLite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
public class SQLHelper
{
static object locker = new object();
readonly SQLiteConnection database;
public SQLHelper()
{
database = GetConnection();
// create the tables
database.CreateTable<Offline>();
database.CreateTable<Category>();
database.CreateTable<Product>();
database.CreateTable<Password>();
}
public SQLiteConnection GetConnection()
{
SQLiteConnection sqlitConnection;
var sqliteFilename = "Offline.db";
IFolder folder = PCLStorage.FileSystem.Current.LocalStorage;
string path = PortablePath.Combine(folder.Path.ToString(),
sqliteFilename);
sqlitConnection = new SQLite.SQLiteConnection(path);
return sqlitConnection;
}
public long Save_password(Password password)
{
lock (locker)
{
if (password.p_id != 0)
{
return database.Update(password);
}
else
{
return database.Insert(password);
}
}
}
}
public class Password
{
[PrimaryKey,AutoIncrement]
public long p_id { set; get; }
public string password { get; set; }
public string type { get; set; }
public string tb_num { get; set; }
}
cs page:
string lbl_1 = e1.Text;
string lbl_2 = e2.Text;
if (lbl_1.Equals(lbl_2))
{
Password password = new Password();
password.password = lbl_2;
long i = App.Database.Save_password(password);
if (i > 0)
{
Debug.WriteLine(i);
DependencyService.Get<IToast>().LongAlert("Success");
}
Navigation.PopAsync();
}
else
{
DependencyService.Get<IToast>().LongAlert("Passwords Mismatch!");
}
sqlite xamarin xamarin.forms
Yes it's already shown in scroll
– Vipin Krishna
Nov 8 at 15:39
I mean there probably is another class where you callSQLHelper.Save_password()and that's not visible in the code block you posted. I'd like to see how/what values you pass within the password parameter when calling the method.
– hankide
Nov 8 at 15:43
Just for clarification, you are inserting the same value over and over again, and not updating, correct?
– Tom
Nov 8 at 16:27
@Tom yes.only one item in table
– Vipin Krishna
Nov 9 at 5:36
i set p_id as return value. the returning p_id is updated...
– Vipin Krishna
Nov 9 at 6:12
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to insert some values into sqlite database. ID has primarykey,autoincrement properties. First value has inserted successfully. When inserting for the second time, ID is not incrementing.So values are inserted again and again,not updating.I have installed sqlite-net-pcl library.Help Please..
using PCLStorage;
using SQLite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
public class SQLHelper
{
static object locker = new object();
readonly SQLiteConnection database;
public SQLHelper()
{
database = GetConnection();
// create the tables
database.CreateTable<Offline>();
database.CreateTable<Category>();
database.CreateTable<Product>();
database.CreateTable<Password>();
}
public SQLiteConnection GetConnection()
{
SQLiteConnection sqlitConnection;
var sqliteFilename = "Offline.db";
IFolder folder = PCLStorage.FileSystem.Current.LocalStorage;
string path = PortablePath.Combine(folder.Path.ToString(),
sqliteFilename);
sqlitConnection = new SQLite.SQLiteConnection(path);
return sqlitConnection;
}
public long Save_password(Password password)
{
lock (locker)
{
if (password.p_id != 0)
{
return database.Update(password);
}
else
{
return database.Insert(password);
}
}
}
}
public class Password
{
[PrimaryKey,AutoIncrement]
public long p_id { set; get; }
public string password { get; set; }
public string type { get; set; }
public string tb_num { get; set; }
}
cs page:
string lbl_1 = e1.Text;
string lbl_2 = e2.Text;
if (lbl_1.Equals(lbl_2))
{
Password password = new Password();
password.password = lbl_2;
long i = App.Database.Save_password(password);
if (i > 0)
{
Debug.WriteLine(i);
DependencyService.Get<IToast>().LongAlert("Success");
}
Navigation.PopAsync();
}
else
{
DependencyService.Get<IToast>().LongAlert("Passwords Mismatch!");
}
sqlite xamarin xamarin.forms
I am trying to insert some values into sqlite database. ID has primarykey,autoincrement properties. First value has inserted successfully. When inserting for the second time, ID is not incrementing.So values are inserted again and again,not updating.I have installed sqlite-net-pcl library.Help Please..
using PCLStorage;
using SQLite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
public class SQLHelper
{
static object locker = new object();
readonly SQLiteConnection database;
public SQLHelper()
{
database = GetConnection();
// create the tables
database.CreateTable<Offline>();
database.CreateTable<Category>();
database.CreateTable<Product>();
database.CreateTable<Password>();
}
public SQLiteConnection GetConnection()
{
SQLiteConnection sqlitConnection;
var sqliteFilename = "Offline.db";
IFolder folder = PCLStorage.FileSystem.Current.LocalStorage;
string path = PortablePath.Combine(folder.Path.ToString(),
sqliteFilename);
sqlitConnection = new SQLite.SQLiteConnection(path);
return sqlitConnection;
}
public long Save_password(Password password)
{
lock (locker)
{
if (password.p_id != 0)
{
return database.Update(password);
}
else
{
return database.Insert(password);
}
}
}
}
public class Password
{
[PrimaryKey,AutoIncrement]
public long p_id { set; get; }
public string password { get; set; }
public string type { get; set; }
public string tb_num { get; set; }
}
cs page:
string lbl_1 = e1.Text;
string lbl_2 = e2.Text;
if (lbl_1.Equals(lbl_2))
{
Password password = new Password();
password.password = lbl_2;
long i = App.Database.Save_password(password);
if (i > 0)
{
Debug.WriteLine(i);
DependencyService.Get<IToast>().LongAlert("Success");
}
Navigation.PopAsync();
}
else
{
DependencyService.Get<IToast>().LongAlert("Passwords Mismatch!");
}
sqlite xamarin xamarin.forms
sqlite xamarin xamarin.forms
edited Nov 9 at 6:03
asked Nov 8 at 13:43
Vipin Krishna
319
319
Yes it's already shown in scroll
– Vipin Krishna
Nov 8 at 15:39
I mean there probably is another class where you callSQLHelper.Save_password()and that's not visible in the code block you posted. I'd like to see how/what values you pass within the password parameter when calling the method.
– hankide
Nov 8 at 15:43
Just for clarification, you are inserting the same value over and over again, and not updating, correct?
– Tom
Nov 8 at 16:27
@Tom yes.only one item in table
– Vipin Krishna
Nov 9 at 5:36
i set p_id as return value. the returning p_id is updated...
– Vipin Krishna
Nov 9 at 6:12
add a comment |
Yes it's already shown in scroll
– Vipin Krishna
Nov 8 at 15:39
I mean there probably is another class where you callSQLHelper.Save_password()and that's not visible in the code block you posted. I'd like to see how/what values you pass within the password parameter when calling the method.
– hankide
Nov 8 at 15:43
Just for clarification, you are inserting the same value over and over again, and not updating, correct?
– Tom
Nov 8 at 16:27
@Tom yes.only one item in table
– Vipin Krishna
Nov 9 at 5:36
i set p_id as return value. the returning p_id is updated...
– Vipin Krishna
Nov 9 at 6:12
Yes it's already shown in scroll
– Vipin Krishna
Nov 8 at 15:39
Yes it's already shown in scroll
– Vipin Krishna
Nov 8 at 15:39
I mean there probably is another class where you call
SQLHelper.Save_password() and that's not visible in the code block you posted. I'd like to see how/what values you pass within the password parameter when calling the method.– hankide
Nov 8 at 15:43
I mean there probably is another class where you call
SQLHelper.Save_password() and that's not visible in the code block you posted. I'd like to see how/what values you pass within the password parameter when calling the method.– hankide
Nov 8 at 15:43
Just for clarification, you are inserting the same value over and over again, and not updating, correct?
– Tom
Nov 8 at 16:27
Just for clarification, you are inserting the same value over and over again, and not updating, correct?
– Tom
Nov 8 at 16:27
@Tom yes.only one item in table
– Vipin Krishna
Nov 9 at 5:36
@Tom yes.only one item in table
– Vipin Krishna
Nov 9 at 5:36
i set p_id as return value. the returning p_id is updated...
– Vipin Krishna
Nov 9 at 6:12
i set p_id as return value. the returning p_id is updated...
– Vipin Krishna
Nov 9 at 6:12
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208991%2fxamarin-forms-sqlite-id-autoincrement-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yes it's already shown in scroll
– Vipin Krishna
Nov 8 at 15:39
I mean there probably is another class where you call
SQLHelper.Save_password()and that's not visible in the code block you posted. I'd like to see how/what values you pass within the password parameter when calling the method.– hankide
Nov 8 at 15:43
Just for clarification, you are inserting the same value over and over again, and not updating, correct?
– Tom
Nov 8 at 16:27
@Tom yes.only one item in table
– Vipin Krishna
Nov 9 at 5:36
i set p_id as return value. the returning p_id is updated...
– Vipin Krishna
Nov 9 at 6:12