Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Customer GetCustomerById(int id)
- {
- using (SqlConnection sqlConn = new SqlConnection(this.connectionString))
- {
- SqlCommand cmd = new SqlCommand("SELECT c.id, c.fname FROM dbo.Customer AS c WHERE c.id =@id", sqlConn);
- cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
- sqlConn.Open();
- SqlDataReader reader = cmd.ExecuteReader();
- bool isRead = reader.Read();
- return new Customer()
- {
- CustomerID = reader.GetInt32(0),
- Name = reader.GetString(1)
- };
- }
- }
- public static bool IsServerConnected(string connectionString)
- {
- using (SqlConnection sqlConn = new SqlConnection(connectionString))
- {
- try
- {
- sqlConn.Open();
- return true;
- }
- catch (SqlException)
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement