Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version = "1.0" encoding = "utf-8"?>
- <resources>
- <string name = "HelloXamarin">Server</string>
- <string name = "ApplicationName">connect</string>
- <string name = "app_name">connect</string>
- <string name = "ButtonClick">Connect</string>
- <string name = "username">Username</string>
- <string name = "database">Database</string>
- <string name = "password">Password</string>
- </resources>
- <?xml version = "1.0" encoding = "utf-8"?>
- <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
- android:orientation = "vertical"
- android:background = "#d3d3d3"
- android:layout_width = "fill_parent"
- android:layout_height = "fill_parent">
- <TextView
- android:text = "@string/HelloXamarin"
- android:textAppearance = "?android:attr/textAppearanceLarge"
- android:layout_width = "match_parent"
- android:layout_height = "wrap_content"
- android:id = "@+id/textView2"
- android:textColor = "@android:color/black" />
- <EditText
- android:id="@+id/plain_text_input"
- android:layout_height="wrap_content"
- android:layout_width="match_parent"
- android:inputType="text"/>
- <TextView
- android:text = "@string/database"
- android:textAppearance = "?android:attr/textAppearanceLarge"
- android:layout_width = "match_parent"
- android:layout_height = "wrap_content"
- android:id = "@+id/database"
- android:textColor = "@android:color/black" />
- <EditText
- android:id="@+id/database_text_input"
- android:layout_height="wrap_content"
- android:layout_width="match_parent"
- android:inputType="text"/>
- <TextView
- android:text = "@string/username"
- android:textAppearance = "?android:attr/textAppearanceLarge"
- android:layout_width = "match_parent"
- android:layout_height = "wrap_content"
- android:id = "@+id/username"
- android:textColor = "@android:color/black" />
- <EditText
- android:id="@+id/username_text_input"
- android:layout_height="wrap_content"
- android:layout_width="match_parent"
- android:inputType="text"/>
- <TextView
- android:text = "@string/password"
- android:textAppearance = "?android:attr/textAppearanceLarge"
- android:layout_width = "match_parent"
- android:layout_height = "wrap_content"
- android:id = "@+id/password"
- android:textColor = "@android:color/black" />
- <EditText
- android:id="@+id/password_text_input"
- android:layout_height="wrap_content"
- android:layout_width="match_parent"
- android:inputType="text"/>
- <Button
- android:id = "@+id/MyButton"
- android:layout_width = "fill_parent"
- android:layout_height = "wrap_content"
- android:text = "@string/ButtonClick" />
- </LinearLayout>
- using System;
- using Android.App;
- using Android.Content;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using Android.OS;
- using System.Data.SqlClient;
- //using System.Data.Sql;
- namespace first
- {
- [Activity(Label = "@string/app_name", MainLauncher = true)]
- public class MainActivity : Activity
- {
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.activity_main);
- Button button = FindViewById<Button>(Resource.Id.MyButton);
- button.Click += delegate {
- // button.Text = "Hello world I am your first App";
- string connectionString = @"Server='test';Database='connect';User Id='test';Password='test';Trusted_Connection=true";
- string databaseTable = "Connect";
- //string referenceAccountNumber = "0001134919";
- string selectQuery = String.Format("SELECT * FROM {0} ", databaseTable);
- try
- {
- using (SqlConnection connection = new SqlConnection(connectionString))
- {
- //open connection
- connection.Open();
- button.Text = "Connection Successful";
- SqlCommand command = new SqlCommand(selectQuery, connection);
- command.Connection = connection;
- command.CommandText = selectQuery;
- var result = command.ExecuteReader();
- //check if account exists
- var exists = result.HasRows;
- }
- }
- catch (Exception exception)
- {
- #region connection error
- AlertDialog.Builder connectionException = new AlertDialog.Builder(this);
- connectionException.SetTitle("Connection Error");
- connectionException.SetMessage(exception.ToString());
- connectionException.SetNegativeButton("Return", delegate { });
- connectionException.Create();
- connectionException.Show();
- #endregion
- }
- };
- }
- }
- }
Add Comment
Please, Sign In to add comment