zephirus Posted June 17, 2009 at 03:44 PM Report Share #273114 Posted June 17, 2009 at 03:44 PM Olá, Tenho uma tabela de nome 'xpto' com 3 items: 'a', 'b' e 'c'. Pretendo ler a última entrada dessa tabela. Sei que o comando SQlite é este: SELECT LAST(column_name) FROM table_name Como eu pretendo todas as colunas, sei que funciona assim: SELECT LAST(a), LAST(b), LAST© FROM xpto Mas depois não consigo ler os três items para colocá-los numa listview. O meu código é este: Dim SQLconnect As New SQLiteConnection() Dim SQLcommand As SQLiteCommand SQLconnect.ConnectionString = "Data Source=" & appPath & "database.db3;" SQLconnect.Open() SQLcommand = SQLconnect.CreateCommand SQLcommand.CommandText = "SELECT LAST(a), LAST(b), LAST(c) FROM xpto" Dim SQLreader As SQLiteDataReader = SQLcommand.ExecuteReader() While SQLreader.Read() Dim lvi As New ListViewItem Dim lvsi1 As New ListViewItem.ListViewSubItem Dim lvsi2 As New ListViewItem.ListViewSubItem lvi.Name = "a" lvi.Text = SQLreader("a") lvsi1.Name = "b" lvsi1.Text = SQLreader("b") lvsi2.Name = "c" lvsi2.Text = SQLreader("c") lvi.SubItems.Add(lvsi1) lvi.SubItems.Add(lvsi2) MainForm.listview1.Items.Add(lvi) End While SQLcommand.Dispose() SQLconnect.Close() Isto não está a funcionar. Alguma ideia? Link to comment Share on other sites More sharing options...
RicardoBastos Posted June 17, 2009 at 03:50 PM Report Share #273118 Posted June 17, 2009 at 03:50 PM lvi.Name = "a" lvsi1.Name = "b" lvsi2.Name = "c" porque fazes isto? Link to comment Share on other sites More sharing options...
zephirus Posted June 17, 2009 at 03:55 PM Author Report Share #273123 Posted June 17, 2009 at 03:55 PM lvi.Name = "a" lvsi1.Name = "b" lvsi2.Name = "c" porque fazes isto? Não é obrigatório, é verdade. Acho que vi isso num exemplo qualquer e deixei. Já agora, nesta página, é possível ver que é possível usar o comando como eu exemplifiquei: http://www.w3schools.com/Sql/sql_tryit.asp Será que o SQLite não suporta a função LAST? Se for esse o caso, como poderei ir ler a última linha? Link to comment Share on other sites More sharing options...
bruno1234 Posted June 17, 2009 at 08:47 PM Report Share #273182 Posted June 17, 2009 at 08:47 PM Experimenta dar nome á coluna: Select Last(Coluna) as Nome from Tabela Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
zephirus Posted June 17, 2009 at 09:24 PM Author Report Share #273198 Posted June 17, 2009 at 09:24 PM Experimenta dar nome á coluna: Select Last(Coluna) as Nome from Tabela Também tentei isso e não deu mas entretanto já resolvi. Fiz assim: SQLcommand.CommandText = "SELECT * FROM xpto WHERE a IN (SELECT MAX(a) FROM xpto)" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now