Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public Customer GetCustomerById(int id)
  2. {
  3. using (SqlConnection sqlConn = new SqlConnection(this.connectionString))
  4. {
  5. SqlCommand cmd = new SqlCommand("SELECT c.id, c.fname FROM dbo.Customer AS c WHERE c.id =@id", sqlConn);
  6. cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
  7. sqlConn.Open();
  8. SqlDataReader reader = cmd.ExecuteReader();
  9. bool isRead = reader.Read();
  10.  
  11. return new Customer()
  12. {
  13. CustomerID = reader.GetInt32(0),
  14. Name = reader.GetString(1)
  15. };
  16. }
  17. }
  18.  
  19. public static bool IsServerConnected(string connectionString)
  20. {
  21. using (SqlConnection sqlConn = new SqlConnection(connectionString))
  22. {
  23. try
  24. {
  25. sqlConn.Open();
  26. return true;
  27. }
  28. catch (SqlException)
  29. {
  30.  
  31. return false;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement