PDA

View Full Version : سوال: دیتا بیس ویندوز فون 8.1 (windows phone 8.1)



m.h.bayan
یک شنبه 08 تیر 1393, 12:54 عصر
سلام دوستان
من یه برنامه برای ویندوز فون 8.1 با SQLite نوشتم ولی مشکل دارم چون هیچ دیتایی ذخیره نمی کنه و نمی دونم مشکل از کجاست در صورتی که هیچ اروری ندارم

mainpage.xaml.cs
using System;using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp2.Resources;
using SQLitePCL;


namespace PhoneApp2
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();


// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
public class custumer
{
public long ID;
public string Fname;
public string Lname;
public long AGE;
}


private void Insert(SQLiteConnection db)
{


try
{
using (var custm = db.Prepare("INSERT INTO Customer ( FN , LN , Age) VALUES (? , ? , ?)"))
{
custm.Bind(1, TB_Fname.Text);
custm.Bind(2, TB_Lname.Text);
custm.Bind(3, Convert.ToInt32(TB_age.Text));
custm.Step();
}
}
catch (Exception ex)
{


}
}
private void Select(SQLiteConnection db)
{


custumer cus = null;
using (var custom = db.Prepare("SELECT ID , FN , LN , Age FROM Customer WHERE Age = ?"))
{
custom.Bind(1, Convert.ToInt32(TB_search.Text));
if (SQLiteResult.DONE == custom.Step())
{
cus = new custumer()
{
ID = (long)custom[0],
Fname = (string)custom[1],
Lname = (string)custom[2],
AGE = (long)custom[3]


};
LB_search.Items.Add("mmm");
}
}


}
public static SQLiteConnection conn;


private void BT_save_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
conn = new SQLiteConnection("myDBtest.db");
Insert(conn);
}


private void BT_search_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
conn = new SQLiteConnection("myDBtest.db");
Select(conn);
}


creatdatabase.cs

using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SQLitePCL;


namespace PhoneApp2
{
public class CreatDatabase
{
public static void CreateDB(SQLiteConnection db)
{


string sql = @"CREATE TABLE IF NOT EXISTS
Customer (Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
FN VARCHAR( 140 ),
LN VARCHAR( 140 ),
Age VARCHAR( 140 )
);";
using (var statement = db.Prepare(sql))
{
statement.Step();
}
}
}
}




app.xaml.cs

public static SQLiteConnection conn; // Code to execute when a contract activation such as a file open or save picker returns
// with the picked file or other return values
private void Application_ContractActivated(object sender, Windows.ApplicationModel.Activation.IActivatedEven tArgs e)
{
conn = new SQLiteConnection("myDBtest.db");
CreatDatabase.CreateDB(conn);
}


// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
conn = new SQLiteConnection("myDBtest.db");
CreatDatabase.CreateDB(conn);
}


// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
conn = new SQLiteConnection("myDBtest.db");
CreatDatabase.CreateDB(conn);
}