C# SQL SELECT Statement
Posted
by
Feren6
on Stack Overflow
See other posts from Stack Overflow
or by Feren6
Published on 2012-09-05T15:34:26Z
Indexed on
2012/09/05
15:38 UTC
Read the original article
Hit count: 151
I have the following code:
SqlCommand cmd2 = new SqlCommand("SELECT ClaimId FROM tblPayment WHERE PaymentId = " + PaymentID.ToString(), mvarDBConn);
SqlDataReader reader = cmd2.ExecuteReader();
reader.Read();
Int32 ClaimId = reader.GetInt32(0);
reader.Close();
If I run the SELECT statement in SQL it returns the number fine, but when I use ExecuteReader all it returns is 0. I've tried multiple methods including ExecuteScalar, ExecuteNonQuery, reader.GetString then casting that to an int, etc.
What am I missing? Thanks.
© Stack Overflow or respective owner