Ich möchte Daten von Xamarin-Anwendung über einen Webdienst an SQL Server speichern. Ich habe versucht, Xamarin Android mit SQL Server über Web-Service zu verbinden, aber fehlgeschlagen.Wie mit SQL Server von Xamarin über Web-Service interagieren?
Web:
SqlConnection conn = new SqlConnection(@"Data Source=my-PC\SQLEXPRESS;Initial Catalog=remotedb;Integrated Security=True");
SqlCommand com;
public Service1() {
[WebMethod]
public string insert(string name)
{
com = new SqlCommand("insert into dinesh values('" + name + "')", conn);
conn.Open();
com.ExecuteNonQuery();
conn.Close();
return "Hello World";
}
Android:
public class Activity1 : Activity
{
localhost.Service1 suresh = new localhost.Service1();
string dinesh;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.MyButton);
EditText e1 = FindViewById<EditText>(Resource.Id.editText1);
button.Click += delegate {
dinesh = suresh.insert(e1.Text);
};
}
}
Gibt es etwas, muss ich sonst ändern oder etwas?
Danke Mann, ich versuche und werde Sie danach wissen lassen. : D –