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!");
}









share|improve this question
























  • 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















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!");
}









share|improve this question
























  • 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













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!");
}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings