Hello,
Could you help me please wit this code? I need to insert this data to my sql server table
using System; using System.Data.SqlClient; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS;
namespace Food_Service { [Activity(Label = "Food_Service", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
System.Data.SqlClient.SqlConnection con;
string toast;
TextView txt;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner1);
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource(
this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = "Server=172.18.64.128; Database=Catalogo; User Id=Mccain; Password= mccain01";
Button button = FindViewById<Button>(Resource.Id.MyButton);
SqlCommand cmd = new SqlCommand();
try
{
con.Open();
cmd.CommandText = "Insert Into Vendedore2 (Vendedor) values('" + txt.Text + "')";
cmd.Connection = con;
cmd.ExecuteNonQuery();
button.Click += delegate { button.Text = string.Format("Conexion exitosa"); };
}
catch
{
button.Click += delegate { button.Text = string.Format("Conexion no exitosa"); };
}
}
public void spinner_ItemSelected (object sender, AdapterView.ItemSelectedEventArgs e)
{
Spinner spinner = (Spinner)sender;
txt = (TextView)FindViewById(Resource.Id.textView1);
toast = string.Format ("{0}", spinner.GetItemAtPosition (e.Position));
Toast.MakeText (this, toast, ToastLength.Long).Show ();
txt.Text = toast;
}
}
}