0

In my WPF-application, I want to start a window only to be shown, if there a no data in the table "Betrieb". So, I know that I can check this with "select count from Betrieb". My problem is, how to get the count into my application.

int i = cmd.ExecuteNonQuery();

is wrong and does not work.

Does anybody have advice?

3 Answers 3

4

use

Convert.ToInt32(cmd.ExecuteScalar())
Sign up to request clarification or add additional context in comments.

Comments

2
Object i = cmd.ExecuteScalar(); 

This method returns an object value with the count and you can cast the object type you want.

Comments

1

By the way if your query is like this you must get an error. Change your query like this:

select count(**Column_Name**) from Betrieb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.