Reputation: 77
I am making Android App in Visual Studio Xamarin, in App's Login screen when the connection is made with DataBase through Web Services for verification of password I want to show a progressDialog until connection is made.
Here's my code on the onclient side:
private string login()
{
string x = null;
var progress = ProgressDialog.Show(this, "waiting", "Loading");
progress.SetProgressStyle(ProgressDialogStyle.Spinner);
new Thread(new ThreadStart(delegate
{
RunOnUiThread(async () =>
{
x = await services.Verification("abc", "xyz");
progress.Dismiss();
});
})).Start();
return x;
}
On the server side:
public string Verification(string userName, string password)
{
SqlConnection conn = new SqlConnection(@"");
conn.Open();
string query = "select category from ACCOUNTS where loginId = '" + userName + "' and pasword= '" + password + "'";
SqlCommand cmd = new SqlCommand(query);
cmd.Connection = conn;
string catagory = null;
SqlDataReader account = cmd.ExecuteReader();
if (account.HasRows)
{
if (account.Read())
{
catagory = account[0].ToString();
}
}
conn.Close();
return catagory;
}
Here's the error in login() function on line x = await services.Verification("abc", "xyz");
and it says:
'String' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'String' could be found (are you missing a using directive or an assembly reference?)
Upvotes: 2
Views: 19089
Reputation: 50728
To use this:
x = await services.Verification("abc", "xyz");
You have to use an API like:
public async Task<string> Verification(string userName, string password)
However, what are you using to communicate with the DB? It looks like you are directly calling the Verification method directly, instead of invoking the service through REST. Calling the method directly won't work when you deploy the app... You need to invoke a proxy to a web service using HttpClient with async/await, RestSharp, or others defined in this tutorial: https://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/.
Taken from here:
var httpClient = new HttpClient();
Task<string> contentsTask = httpClient.GetStringAsync("http://xamarin.com");
string contents = await contentsTask;
Upvotes: 1