Home SqlDataReader returns empty
Reply: 0

SqlDataReader returns empty

user943 Published in June 21, 2018, 8:42 am

Here's my code:

static void Main(string[] args)
            SqlConnection _sqlConnection = new SqlConnection (@"Data Source=(local)\SQLEXPRESS;Integrated Security=SSPI;" + "Initial Catalog=OnlineBanking");
            var cmdSelect = new SqlCommand("Select * from BankAccounts where AccountId = 1", _sqlConnection);
            using (SqlDataReader dataReader = cmdSelect.ExecuteReader())
                if (dataReader.HasRows)
                    float AccountBalance = (float)dataReader["Balance"];
                    Console.WriteLine("{0}", AccountBalance);

This line

 float AccountBalance = (float)dataReader["Balance"];

causes problems, as dataReader returns empty. How can I fix it? What's the issue?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312339 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO