Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed an Asp.net web project and i need to create an Andriod app same functionality as in C# coding and can we connect with SQL Server in Xamarin ?

is it possible to develop an android app with the functionality like gridview with selected index change,rowdatabound and many more.
Posted

 
Share this answer
 
Comments
Maciej Los 10-Oct-14 8:59am    
+5!
If you wrap your SQL calls in a web service then you can invoke them in your Android app.
 
Share this answer
 
Comments
Maciej Los 10-Oct-14 8:59am    
+5!
Hi,

Yes you can create all functionality which developed in web asp.net grid etc..

For Grid functions use List View, which can be custom designed to view all items in a grid ..

For connecting it to SQL Server write WCF / JSON format service.. and host the service in web server.


Upload Data from Xamarin Android to Remote Server


C#
List    listToServer = new List< Student >();
            try
            {
                listToServer.Clear();
                
                     
                new Java.Lang.Thread(() =>
                    {
                       listToServer.Add(exCloud);
                         string jsonstr =   JsonConvert.SerializeObject (Student);

                        ASCIIEncoding encoding = new ASCIIEncoding();

                        byte[] data = encoding.GetBytes(jsonstr);

 
                        string webStr = "http://sampleStudent.com/wcf/ExcelData.svc/json/StudentDetails";

                        HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(webStr);
                        webrequest.Method = "POST";
                        webrequest.ContentType = "application/x-www-form-urlencoded";
                        webrequest.ContentLength = data.Length;
                        Stream newStream = webrequest.GetRequestStream();
                        newStream.Write(data, 0, data.Length);
                        newStream.Close();
                        HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
                        Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
                        StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
                        string message=loResponseStream.ReadToEnd();


                        RunOnUiThread(() => onSuccessfulLogincl(message));

                    }).Start();




              
                
            }
            catch (Exception ex)
            {

                Toast.MakeText (this, ex.Message, ToastLength.Long).Show ();
            }



Sending Data to Server from Android Xamarin

C#
ListgetDataFromServer()
        {
            List StudentList = new List ();
            try
            {
                WebClient client = new WebClient ();
                string webStr;




                webStr = "http://sampleStudent.com/wcf/ExcelData.svc/json/students";
                HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create (webStr);

                webrequest.Method = "GET";
                webrequest.ContentType = "application/x-www-form-urlencoded";

                HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse ();
                Encoding enc = System.Text.Encoding.GetEncoding ("utf-8");
                StreamReader loResponseStream = new StreamReader (webresponse.GetResponseStream (), enc);

                string JsonString = loResponseStream.ReadToEnd ();




                StudentList = Deserialise> (JsonString);


                webresponse.Close ();
                loResponseStream.Close ();


                RunOnUiThread (() =>HideProgress () );

            }
            catch (Exception ex)
            {
                Toast.MakeText (this,ex.Message, ToastLength.Long).Show ();
            }


            return StudentList;



        } 



 public static T Deserialise(string json) {
            var obj = Activator.CreateInstance();
            using (var memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(json))) {
                var serializer = new DataContractJsonSerializer(obj.GetType());
                obj = (T) serializer.ReadObject(memoryStream);
                return obj;
            }
        }









Thanks,
Ullas Krishnan
 
Share this answer
 
Comments
24983 12-Mar-15 5:53am    
i used above code Sending Data to Server from Android Xamarin and run it then

throws error "System.Net.WebException: The remote server returned an error: (400) Bad Request."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900