Wpis z mikrobloga

Mam taki #sql :

Select code from issuedcard where year=2018 and month=2 and id=(select max(id) from issuedcard where year=2018 and month=2)


No nic skomplikowanego, ale.. Jak w #visualstudio w "server explorer" daję "new query" to działa tak jak ma działać, natomiast w kodzie przy wywołaniu za pomocą "komenda.executeNonQuery(); " zwraca "-1". Co robię nie tak? Wydaje mi się, że nigdy nie miałem takiego problemu..
#informatyka #pytaniedoeksperta
  • 7
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach

executeNonQuery

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1.

@kiboq: Robisz
  • Odpowiedz
ExecuteScalar


@vytah: Kurde, próbowałem wcześniej scalar i nie działało, teraz patrzę drugi raz.. działa ( ͡° ʖ̯ ͡°)

Dzięki :)
  • Odpowiedz
@EstradaOrNada: Dlatego, że sobie robię for(i=0;i<ilosc id; i++) i pobieram selectem "max(id) - i" czyli po kolei wartości. Nie wiem czy to optymalne rozwiązanie ale rekordów jest kilkadziesiąt, a potrzebuję to tylko do generowania wydruku więc na szybkości mi nie zależy.
  • Odpowiedz