private bool isDataBaseConnected() { try { using (SqlConnection objConn = new SqlConnection(OddsConnection2.GetConnectionString())) { if (objConn.State == ConnectionState.Closed) { objConn.Open(); } if (objConn.State == ConnectionState.Open) { objConn.Close(); return(true); } else { return(false); } } } catch (SqlException ex) { return(false); } }
private void GetMatchInfo(int matchid) { try { using (SqlConnection objConn = new SqlConnection(OddsConnection2.GetConnectionString())) { SqlCommand cmd = new SqlCommand("select sportid, (Home +' V ' +Away) as Matchname, MatchDate,Time from MatchInfo where id='" + matchid + "'", objConn); cmd.CommandTimeout = 500; objConn.Open(); SqlDataReader reader; reader = cmd.ExecuteReader(); if (reader.Read()) { lblMatchNmae.Text = reader["Matchname"].ToString(); lblsportid.Text = reader["sportid"].ToString(); lblDate.Text = reader["matchdate"].ToString(); lblTime.Text = reader["Time"].ToString(); } reader.Close(); objConn.Close(); } } catch (Exception ex) { throw new Exception(ex.Message); } }