I created(in last stage) a ASP.NET website which requires database communications, So we created WCF services to connect to the database. If there is a Select statement those service returns DataTable.
Services are working fine and website also working fine
At the time of API creation i don't know that windows phone sdk does not support the DataTables.
I read some where that Windows Phone SDK doesn't support DataTable, i checked in my Visual Studio also there is no class called DataTable in System.Data namespace.
I am new to Windows Phone.
But now we want to create a WINDOWS PHONE APP which also works same as Website, so we want to use the existing API(WCF Service).
is there is any way to accomplish this task. most of the methods return type is DataTable.
we don't want to create two API's(means services). What should I do?
How to create a Service which works for both Windows Phone and Website.
we are ready to change the change the API and according to that ready to update Website also?
thanks
Just changed the API to return Stream instead of DataTable
System.IO.StringWriter reader = new System.IO.StringWriter();
dt.WriteXml(reader, XmlWriteMode.WriteSchema);//dt is datatable
return reader;
in website small minor changes, reading the stream and assign it to a datatable
StringReader xmlReader = new StringReader(stream);
DataTable dt = new DataTable();
dt.ReadXml(xmlReader);
Update:
This approach is not suggestible(this was my first web service application), I suggest to use JSON/XML responses(with returning DTOs) instead of returning DataTable..
Following links might land you in right direction.
http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
http://mono.servicestack.net/ServiceStack.Hello/
Not sure why you used datatable. Do you mean dataset?
They are all XML under the covers. Try parsing them. Try something like this:
var resultNewDataSet = XElement.Parse(xmlContent);
var result = resultNewDataSet.Descendants("Table")
.Select(t => new
{
aaa = t.Descendants("aaa").First().Value,
bbb = t.Descendants("bbb").First().Value
});
foreach (var res in result)
{
System.Diagnostics.Debug.WriteLine("aaa: " + res.aaa + " / bbb: " + res.bbb);
}
Related
I am trying to build an Android Xamarin Application. I have created an SQLite database named regjistri.sqlite . The database it's not corrupted, I can open it via SQLite browser on my PC. This database I have save it to my android Documents folder.
I am trying to access it like below via sqlite-net-pcl library.
string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "regjistri.sqlite");
var db = new SQLiteConnection(dbPath);
var data = db.Query<object>("SELECT COUNT(*) FROM tblLidhja ");
Also I have gice the application the reading and writing permissions. When I debug it via USB cable, it give me the "SQLite.SQLiteException: no such table: tblLidhja" exception. Can someone help me whats may be wrong, or what should I change to read some data?
Before getting data , first need to check whether this table is exist in data base .You can refer to this document to check .
By the way ,having a try with this way to get count from database:
var db = new SQLiteConnection("DbPath");
var stocksStartingWithA = db.Query<TableName>("SELECT * FROM DbNmae ");
int count = stocksStartingWithA.Count; //get count from table
Here is similar discussion with java code, but it also can be refer in xamrin project.
My app uses Xamarin.Forms.Maps to display a map and also for geocoding. The map is displayed on a separate page when the user navigates to it from the main page. I use the geocoder to reverse geocode the current location so that I have the address. This is done from various places other than the map page.
When I run the app on a device (even in debug mode) the geocoder works right away in iOS and Android, but does not work in UWP. After I navigate to the map page and display the map, then go back to a different page to use the geocoder it starts working.
I saw a thread about the map not working with release build so I added the following code:
var laRendererAssemblies = new[] { typeof(Xamarin.Forms.Maps.UWP.MapRenderer).GetTypeInfo().Assembly };
Xamarin.Forms.Forms.Init(e, laRendererAssemblies);
//Xamarin.Forms.Forms.Init(e);
Xamarin.FormsMaps.Init("MyBingMapsKey");
This has not helped the issue with the Xamarin.Forms.Maps.Geocoder. I also tried creating an instance of Xamarin.Forms.Maps.Map in my main page, but that did not help either. Is there a way to prime the map component so that the Geocoder will work on a device? (My test device is ARM, but it happens when I run on Local
Machine (Win 10) too)
Following is a snippet of the call to the Geocoder (which works fine once the user has navigated to the Map page and back - and it works fine in iOS and Android - and as such I don't believe it is a problem with the code, but here it is):
public static async Task<Plugin.Geolocator.Abstractions.Position> Geocode(string address)
{
try
{
var loGeocoder = new Xamarin.Forms.Maps.Geocoder();
System.Diagnostics.Debug.WriteLine("Get Lat/Lon");
var lcolPositions = await loGeocoder.GetPositionsForAddressAsync(address);
if (lcolPositions != null)
After doing some research and ensuring that your geodecode class being static wouldn't mess with the async/await pattern in the UWP build. I've come across a few references to this particular problem with the built in Forms.Map geodecoder elsewhere, not just for UWP it has also been noted for android‡.
I took some time to have a look at one of our current cross-platform applications that we have in the app stores, and according to our internal documentation we switched out both the xamarin.forms map, and the geodecoder for custom ones.
The plugin that we use for our cross-platform application is the 'GelocatorPlugin' created by james montemagno, and can be found here.
It can be added to your project as a Nuget package if you prefer, and the implementation of it is very similar to the default one, so there's very little code to change. The primary benefit is that the UWP element of the geodecode plugin has been modified to take into account windows advanced tracking scenarios (details found here).
It should be a lot more stable than the one your using, once installed you simply use it like so:
Reverse Geocoding
Based on a location that is passed in, thi swill grab a list of
addresses.
UWP requires a Bing Map Key, which you can acquire by reading this
piece of documentation.
try
{
var addresses = await locator.GetAddressesForPositionAsync (position, string mapKey = null);
var address = addresses.FirstOrDefault();
if(address == null)
Console.WriteLine ("No address found for position.");
else
Console.WriteLine ("Addresss: {0} {1} {2}", address.Thoroughfare, address.Locality, address.Country);
}
catch(Exception ex)
{
Debug.WriteLine("Unable to get address: " + ex);
}
‡ Links to similar problems - Link 1, Link 2
resolved after added following lines in APP.xaml.cs (UWP project)
Xamarin.FormsMaps.Init("bingmapkey");
Windows.Services.Maps.MapService.ServiceToken = "bingmapkey";
I want to Export a table from my database to an excel file on the server and then download it. The following is the code that I developed for this purpose:
import flash.net.FileReference;
import flash.net.URLRequest;
public function sqlDownloadExcel():void {
var http:HTTPService = new HTTPService;
var parm:Object = new Object;
var sql:String;
sql = "insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\\inetpub\wwwroot\\myApp\\App_Data\\myExport.xls;', 'SELECT * FROM [Sheet1$]') SELECT * FROM myTable";
parm.sql = sql;
parm.db = "myDatabase";
http.url = "http://mywebsite.com/SQLconnector/sqlconnector.asp?irand="+Math.random();
http.showBusyCursor = true;
http.request = sql;
http.addEventListener(ResultEvent.RESULT, function(e:ResultEvent):void {sqlDownloadExcelResult(e);});
http.addEventListener(FaultEvent.FAULT, mssqlFault);
http.method = "POST";
sqlToken = http.send(parm);
}
public function sqlDownloadExcelResult(event:ResultEvent):void{
var request:URLRequest = new URLRequest("http://mywebsite/myApp/App_Data/myExport.xls");
var fileRef:FileReference = new FileReference();
fileRef.download(request);
}
The code creates the Excel file on the server correctly, but running the fileRef.download(request) functions causes the following error:
Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.
Any advice would be much appreciated.
Thank you
You can't do what you want. Security restrictions prevent your app from trying to download anything to the clieht machine without user input. That is why you're seeing the error.
I recommend creating the excel sheet on the server, saving it to the server, and then sending a URL back to your Flex app. Use navigateToURL() to open it; and the browser should handle it based on the client's browsers settings. It may download automatically; or open automatically; or it may prompt the user what it wants to do.
If necessary, you can create a server side script to routinely clean out the generated files.
Based on the code you provided, it looks like you are 90% of the way there. Just instead of using FileReference to try to download the file, use navigateToURL() to open that URLRequest.
Alternatively, you could modify your UI to say "You're file is ready, click here to get it" or something similar. Then you have user interaction and can open the download window after the user clicks the button.
I am working on an application for Windows Phone 7.1 (outdated, I know) and I need to show information about different users, which is in a data base. The way I have to do it (schedules) is through a method in an ASP.NET web service that outputs a dataset. What I have in mind is that maybe there's a way to convert this data set into multiple strings, or even an array, just as long as Windows Phone 7 supports it.
So, how can I translate this dataset into a format I can work with?
The following is the web service method. Variables are in spanish and I rather not translate it and mess something up. Apologies for that.
public DataSet Listar_Usuario() //List_User
{
DataSet DS = new DataSet();
abrirconexion(); //openconnection
query.CommandText = "LISTAR_USUARIO"; //LIST_USER
query.CommandType = CommandType.StoredProcedure;
query.Connection = coneccion; //connection
var_adaptador.SelectCommand = query; //var_adapter
var_adaptador.Fill(DS, "Usuario"); //var_adapter
query = null;
cerrarconexion(); //closeconnection
return DS;
}
Do you have to use this method within the ASP.Net service? If not why not have a look at http://pcbl.de/2011/07/20/dataset-on-your-wp7-app/ - it should have everything you need to get around your problem.
we are using the asp.net profiles provider in our app and I need to update one particular property for most of our users. Does anyone have a console app or sample code written? We are not storing the properties in string format. This binary stream is in the aspnet_Profile table.
thanks,
hp
You can do something like this fairly easily:
Membership.GetAllUsers().Cast<MembershipUser>()
.Where(u => true /*insert your criteria here*/)
.ToList().ForEach(user =>
{
var p = ProfileBase.Create(user.UserName, true);
// do whatever you want to the profile here
int counter = (int)p["Counter"];
counter++;
p["Counter"] = counter;
p.Save();
});
The above code will work as-is in any handler of your site, but if you want to do it with a console app, simply copy the <system.web> section from your web.config to the app.config of the console app.
caveat: if you are using the default provider connection string, localSqlServer, you will need to create a new connection string explicitly pointing to the .mdf as only web applications have a concept of DATADIRECTORY (app_data).