1

I have SQL Server 2008 R2 with a table that contains data ordered by numbers from 1 to 99999.

I want to connect to that table and show the last number of the row in my app, automatically without selecting anything.

How I could do it?

Thanks.

HaOx
  • 1,839
  • 6
  • 26
  • 36
  • You cannot do anyting without performing a select statement. Sorry – Oybek Feb 01 '12 at 15:10
  • You can use the following select statement `Select MAX(MyNumberColumn) FROM MyTable` – Oybek Feb 01 '12 at 15:11
  • Are you saying that you want to connect to a table in a SQL Server instance on a PC based machine FROM an Android app? – jwatts1980 Feb 01 '12 at 15:16
  • possible duplicate of [How to connect android to a database server](http://stackoverflow.com/questions/3419697/how-to-connect-android-to-a-database-server) – Mark B Feb 01 '12 at 15:19

2 Answers2

2

If you will connect to the server from your Android App I would recommend using a webservice.

Take a look at this for example:

Rest Webservice

And you don't want to select anything? You can call a Stored Procedure maybe?

Thomas
  • 1,563
  • 3
  • 17
  • 37
1

The SQL:

select top 1 from yourtable order by yournumericfield desc;

Or

select max(yournumericfield) from yourtable;

I notice that this is tagged Android. Android cannot talk directly with SQL Server. The easiest thing to do is to write a web service to sit in between the Android device and SQL Server:

Android --> Web Service -> SQL Server

You can perform standard HTTP communication in Java to talk to the web service. Your web service can talk to SQL Server using ADO in C++, or using the DB libraries in C#, perhaps. Or easier, using a web scripting language like ASP or ASP.NET, you can use the standard Windows DB functions.

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228