Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. private SqlDataReader QueryConnectionString (string query)
  2. {
  3. // New SQL Connection
  4. SqlConnection cnn;
  5.  
  6. // New Connection String
  7. string connetionString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
  8.  
  9. // Instantiate the SQL Connection with Connection String
  10. cnn = new SqlConnection(connetionString);
  11.  
  12. // Create a SqlCommand with the input Query
  13. SqlCommand command = new SqlCommand(query, cnn);
  14.  
  15. cnn.Open();
  16.  
  17. // Create a SqlDataReader and tie it to the query
  18. SqlDataReader reader = command.ExecuteReader();
  19.  
  20.  
  21. cnn.Close();
  22.  
  23. return reader;
  24. }
  25.  
  26. SqlDataReader reader = QueryConnectionString("SELECT * FROM tTable");
  27.  
  28. lblOutput.Text = reader.GetString(0);
  29.  
  30. System.InvalidOperationException: 'Invalid attempt to call CheckDataIsReady when reader is closed.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement