i'm new in xamarin, i need help please,
I have data in my database MySql and i went to import it into a local database Sqlite, i craete a websevice that give me a data in jSon fomart ( sérialize) and now i try to consomme this webservice and get a data in my phone application into a sqlite database, but it doesn't work
can someone help me please
i copy what i tried
Class activitees:
[Table("activitees")]
class activitees
{
public activitees()
{
}
public int id { get; set; }
public string title { get; set; }
public string titlean { get; set; }
}
Class CreateDB
public class CreateDB
{
public string Creer()
{
var sortie = "";
sortie += "création de la bdd";
string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "test.db3");
var db = new SQLiteConnection(dbPath);
sortie += "\nDB creer";
db.CreateTable<activitees>();
return sortie;
}
public async void Readactivitees()
{
var client = new WebClient();
var response = client.DownloadString(new Uri("http://localhost:54001/WebService.asmx"));
List<activitees> activity = JsonConvert.DeserializeObject<List<activitees>>(response);
foreach (activitees obj in activity)
{
//var newActivitees = new activitees();
//newActivitees.title = obj.title;
//activitees.Insert(newActivitees);
// Console.WriteLine(obj.title);
//Console.WriteLine(obj.titlean);
string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "test.db3");
var db = new SQLiteConnection(dbPath);
activitees item = new activitees();
item.title = obj.title;
db.Insert(item);
}
}
Class MainActivity
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Creation de base de donnée
Button btnCreateDB = FindViewById<Button>(Resource.Id.btnCreateDB);
btnCreateDB.Click += btnCreateDB_Click;
Button btnGetActivitees = FindViewById<Button>(Resource.Id.btnGetActivitees);
btnGetActivitees.Click += btnGetActivitees_Click;
}
void btnCreateDB_Click(object sender, EventArgs e)
{
CreateDB dbr = new CreateDB();
var res = dbr.Creer();
Toast.MakeText(this, res, ToastLength.Long).Show();
}
void btnGetActivitees_Click(object sender, EventArgs e)
{
CreateDB dbr = new CreateDB();
dbr.Readactivitees();
}
}
Thank you, hava a good day
Aucun commentaire:
Enregistrer un commentaire