Jak pobrać ilość wierszy zawierających dane id

0
conn = new NpgsqlConnection(connstring);
conn.Open();
//co tutaj?
conn.Close();

Co trzeba wpisać aby sprawdzić czy baza zawiera dane id czy nie zawiera. Próbowałem użyć:

string myCheckIfClientExists = "SELECT id FROM client where id='"+h.ClientId.ToString()+"' LIMIT 1";
NpgsqlCommand ncCheckClient = new NpgsqlCommand(myCheckIfClientExists, conn);
int k = ncCheckClient.ExecuteNonQuery();

Ale k cały czas wynosi -1. Dlaczego nie 0 lub 1?

1

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.** For all other types** of statements, the return value is -1.

1

a co google ci zamknęli??? Przecież to jest w KAŻDYM PODSTAWOWYM kursie!!!

0

Piszę

int k= (int)ncCheckClient.ExecuteScalar(); 

ale to wyrzuca błędy castowania.

0

pomoże ktoś?

0

http://npgsql.projects.postgresql.org/docs/manual/UserManual.html
Pozycja Getting a full result set with NpgsqlCommand.ExecuteReader() method and NpgsqlDataReader

0

"Dobra a jak pobrać ilość wierszy zawierających id"

http://bit.ly/PqSZnr ... ;-)

0
maszynaz napisał(a):

Co trzeba wpisać aby sprawdzić czy baza zawiera dane id czy nie zawiera.

EXISTS?

1 użytkowników online, w tym zalogowanych: 0, gości: 1