1

I have this SqlCommand, but i dont know, how i give the return value?

string param = Request.QueryString["id"];
System.Data.SqlClient.SqlConnection se = new System.Data.SqlClient.SqlConnection(GetConnectionString());
            {
                System.Data.SqlClient.SqlCommand cme;
                se.Open();
                cme = new System.Data.SqlClient.SqlCommand("select Sum(case when (Domaci_tym = 'Tupesy') then Domaci_branky else Hoste_branky end) from Zapas AS branky where (ID_zapas=@ID_zapas)", se);
                cme.Parameters.AddWithValue("@ID_zapas", param);
                cme.ExecuteNonQuery();
                se.Close();

1 Answer 1

4

Change this line cme.ExecuteNonQuery(); to:

double sum = 0d;
var result = cme.ExecuteScalar(); //returns object that needs casting to get proper value

if (result != null && double.TryParse(result.ToString(), out sum))
{
    //query returned valid sum
}

More info about that method here

Sign up to request clarification or add additional context in comments.

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.